Last active
December 17, 2015 04:59
-
-
Save curtislacy/5554784 to your computer and use it in GitHub Desktop.
Ubuntu Port Forwarding using iptables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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