Redirect or forward ports in iptables
Redirect or Forward Ports using Iptables
Port Redirection:
iptables -t nat -A PREROUTING -i <interface> -p tcp --dport <port number=""> -j REDIRECT --to-port <port_number></port_number></port></interface>
or
iptables -t nat -I PREROUTING --src ip/mask --dst <ip addr=""> -p tcp --dport 80 -j Redirect --to-port <br></br></ip>
Port Forwarding:
iptables -A PREROUTING -t nat -i <interface> -p tcp --dport 80 -j DNAT --to <ipaddr :port=""></ipaddr></interface>
iptables -A INPUT -p tcp -m state --state NEW --dport 80 -i -j ACCEPT
For a single Source IP :
<br></br>
iptables -A PREROUTING -t nat -i <interface> -p tcp --source x.x.x.x --dport <port_number> -j DNAT --to <port></port></port_number></interface>```