iptables localhost redirection code example
Example 1: iptables localhost redirection
sudo iptables -t nat -A PREROUTING -p tcp -m tcp -s 192.168.4.0/24 --dport 80 -j DNAT --to-destination 192.168.2.4
sudo iptables -t nat -A PREROUTING -p tcp -m tcp -s 192.168.4.0/24 --dport 443 -j DNAT --to-destination 192.168.2.4
Example 2: iptables localhost redirection
sudo iptables -t nat -A PREROUTING -p tcp -m multiport --dports 443,80 -j DNAT --to-destination 192.168.2.4:80
iptables -t nat -A POSTROUTING -j MASQUERADE