Ubuntu – iptables + nat to internal web server

iptablesUbuntu

We run ubuntu on our gateway machine. We have a DNAT iptables rule sending traffic on 80 and 3306 to an internal ip address that runs a webserver. It doesn't work at all.

eth1 is the wan interface, eth0 is the local one

-A INPUT -p tcp -m tcp -m multiport -s 192.168.2.173 -j ACCEPT --dports 25,80,443,465,3306
-A OUTPUT -d 173.201.37.214 -o eth1 -j ACCEPT
-A PREROUTING -p tcp -d $EXT_IP -i eth1 --dport 80 -j DNAT --to-destination 192.168.2.173:80
-A PREROUTING -p tcp -d  $EXT_IP -i eth1 --dport 3306 -j DNAT --to-destination 192.168.2.173:3306
-A FORWARD -p tcp -d 192.168.2.173 --dport 80 -j ACCEPT

Best Answer

You need the corresponding rules in the filter table to allow the traffic through the filter. The rules you've posted only handle the NAT part.

-A FORWARD -p tcp -d 192.168.2.5 -i eth1 --dport 80 -j ACCEPT
-A FORWARD -p tcp -d 192.168.2.5 -i eth1 --dport 3306 -j ACCEPT

EDIT: OP didn't include full output in first post.