Skip to content

Instantly share code, notes, and snippets.

@SilentKernel
Last active February 16, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SilentKernel/95d9a64add27a56479b32b3053945a96 to your computer and use it in GitHub Desktop.
Save SilentKernel/95d9a64add27a56479b32b3053945a96 to your computer and use it in GitHub Desktop.
Redirect one port to an other host with iptables
# Allowing ipv4 forward
echo 1 > /proc/sys/net/ipv4/ip_forward
# Redirect request response to source
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# Redirect request on port 80 (TCP) to destionation's ip -> port 80
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination xx.xx.xx.xx:80
# Allow forwarding of this port
iptables -A FORWARD -i eth0 -p tcp --dport 80 -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment