Skip to content

Instantly share code, notes, and snippets.

@eegrok
Created May 6, 2011 00:18
Show Gist options
  • Save eegrok/958231 to your computer and use it in GitHub Desktop.
Save eegrok/958231 to your computer and use it in GitHub Desktop.
forward traffic with iptables
# 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