Skip to content

Instantly share code, notes, and snippets.

@shamil
Last active September 13, 2018 19:31
Embed
What would you like to do?
how to redirect from one port to another using iptables
# how to redirect from one port to another using iptables
###
# install following package in order to preserve the iptables rules
sudo apt-get install iptables-persistent
# redirect from port 80 to port 8000
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000
# redirect from one IP to other
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A OUTPUT -d <ip-address-1> -j DNAT --to-destination <ip-address-2>
# save iptables rules
sudo /etc/init.d/iptables-persistent save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment