Sunday, March 13, 2011

IPTables Port Forwarding

Since the creation of my new virtual network, I use one VM just to NAT/route packets so everything else is behind that gateway. I was recently searching on how to do port forwarding to the Postfix behind the gateway and I came across several articles that essentially say the same thing. There are just 2 steps to it assuming you have IPTables up and running:


iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 80 -j DNAT --to 192.168.1.50:80
iptables -A INPUT -p tcp -m state --state NEW --dport 80 -i eth1 -j ACCEPT

then to save the rules:
service iptables save
  • eth1 is the external interface that accepts packets
  • 192.168.1.50 is the IP address where packets are forwarded
  • Port 80 is the port that is being forwarded

No comments:

Post a Comment