Port forwarding with iptables

In this tutorial we’ll set up a simple port forwarding (NAT) using iptables. 1. Enable ip forward echo “1” > /proc/sys/net/ipv4/ip_forward 2. Append routing rules to the nat table iptables -t nat -A PREROUTING -p tcp -s 0/0 -d {local_ip} –dport {local_port} -j DNAT –to {destination_ip}:{destination_port} iptables -t nat -A POSTROUTING -o eth0 -d {destination_ip} -j SNAT –to-source {local_ip} {local_ip}: A ip address mapped on the local system {local_port}: The port you would like to listen on {destination_ip}: Destination ip address {destination_port}: Destination port 3. Now you can access http://{local_ip}:{local_port} and would actually be getting response from http://{destination_ip}:{destination_port} A working … Continue reading Port forwarding with iptables