Let's say you want to forward requests going to 80 to a server listening on port 8080.
Note that you will need to make sure port 8080 is allowed, otherwise ufw will block the requests that are redirected to 8080.
sudo ufw allow 8080/tcp
There are no ufw commands for setting up the port forwards, so it must be done via configuraton files. Add the lines below to /etc/ufw/before.rules
, before the filter
section, right at the top of the file:
*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
COMMIT
Then restart and enable ufw to start on boot:
sudo ufw enable