Last active
November 27, 2023 09:34
-
-
Save shamil/3170579 to your computer and use it in GitHub Desktop.
how to redirect from one port to another using 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
# 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