Skip to content

Instantly share code, notes, and snippets.

@curtislacy
Last active December 17, 2015 04:59
Show Gist options
  • Save curtislacy/5554784 to your computer and use it in GitHub Desktop.
Save curtislacy/5554784 to your computer and use it in GitHub Desktop.
Ubuntu Port Forwarding using iptables
# To see the list of forwarding routes:
sudo iptables -L -t nat
# To add a couple new routes:
ubuntu@ip-10-64-50-6:~$ sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 1336
ubuntu@ip-10-64-50-6:~$ sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 1337
# To delete a route (note that the rule number starts at 1!)
ubuntu@ip-10-64-50-6:~$ sudo iptables -t nat -D PREROUTING 3
# To make sure they're persistent (assuming you have iptables-persisent installed.)
ubuntu@ip-10-64-50-6:~$ sudo iptables-save > ./rules.v4 ; sudo cp ./rules.v4 /etc/iptables/rules.v4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment