In this guide, we're going to briefly cover how to do a basic "port forward" with UFW.
The example we're going to use is forwarding traffic from your server's port 80 to a custom defined port. In this instance, our web server is set to only listen to traffic on port 8080, and we want our users to be able to access it by simply using the domain name without a port in the address bar (such as www.domain.tld)
First, we allow the port in UFW. (We're going to toss in a rule for ssh as a good measure just in case it wasn't set beforehand. This way we don't lose access to the server when re-enabling UFW)
sudo ufw allow 8080/tcp sudo ufw allow ssh
Now we are going to add the following text to /etc/ufw/before.rules, before the filter section.
sudo nano /etc/ufw/before.rules
*nat :PREROUTING ACCEPT [0:0] -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 COMMIT
sudo ufw disable sudo ufw enable
Congratulations! Now your traffic for port 80 should be forwarded over to port 8080.
Join our Private Discord Chat to chat with, as well as find community assistance from other Verified SkySilk Users: https://invite.gg/SkySilk
CLICK TO DEPLOY AN UBUNTU LINUX VPS
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article