Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shamil
Last active November 27, 2023 09:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamil/3170579 to your computer and use it in GitHub Desktop.
Save shamil/3170579 to your computer and use it in GitHub Desktop.
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