Created
May 6, 2011 00:18
-
-
Save eegrok/958231 to your computer and use it in GitHub Desktop.
forward traffic with 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
# from http://www.debuntu.org/how-to-redirecting-network-traffic-a-new-ip-using-iptables | |
# enable ip forwarding until reboot | |
echo 1 > /proc/sys/net/ipv4/ip_forward | |
# enable ip forwarding after reboot | |
# edit /etc/sysctl.conf | |
# uncomment line: #net.ipv4.ip_forward=1 | |
# forward all traffic incoming on port 1111 to 2.2.2.2 on port 2222 | |
# note -- PREROUTING happens before traffic arrives at this box, so, on the box you are running this command on, | |
# you cannot test it locally, ala: telnet localhost 1111 -- it won't work because the PREROUTING rule won't get called | |
iptables -t nat -A PREROUTING -p tcp --dport 1111 -j DNAT --to-destination 2.2.2.2:2222 | |
iptables -t nat -A POSTROUTING -j MASQUERADE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment