Last active
February 16, 2017 14:33
-
-
Save SilentKernel/95d9a64add27a56479b32b3053945a96 to your computer and use it in GitHub Desktop.
Redirect one port to an other host 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
# 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