Monday, March 26, 2018

Use iptables on Linux to port forward

IPTABLES on Linux can be configured to replace Web Reverse Proxy in some cases to redirect ports. Below is how on Ubuntu.

Enter command below in SSH session to redirect port 80 to port 8080. Port 8080 will keep working.

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
Verify it it is working. Then make sure the configuration will be loaded every time Linux starts.

sudo iptables-save | sudo tee /etc/iptables.conf
to save your current iptables rules to /etc/iptables.conf and then insert these lines in /etc/rc.local:
# Load iptables rules from this file
iptables-restore < /etc/iptables.conf

No comments: