0

I'm trying to use iptables to forward incoming traffic on port 80 to a web server running on another IP address and port. Not that it appears to make a difference, the web server is running in a Docker container on port 3000. Here's what I've done so far.

Forward incoming traffic on 80 to the web server:

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 172.17.x.x:3000

Remap traffic returning from the web server so the client sees the correct source address:

sudo iptables -t NAT POSTROUTING -s [web server IP address] -j SNAT --to-source 10.0.y.y

However when I view my rules with iptables -L, neither are showing up and I can't access the site from the host's public address. My host is running Ubuntu 14.04 (Trusty) and port forwarding is enabled.

1
  • 2
    You can use iptables -L -n -t nat to list nat rules exclusively. – Diamond Mar 4 '16 at 11:12
0

Check:
a) If your local webserver is using the firewall as default gateway
b) Port forwarding in the firewall

cat /proc/sys/net/ipv4/ip_forward

c) The rules...

# iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.1.2:8080
# iptables -A FORWARD -p tcp -d 192.168.1.2 --dport 8080 -j ACCEPT

These two rules are straight forward. The first one specifies that all incoming tcp connections to port 80 should be sent to port 8080 of the internal machine 192.168.1.2. Then we accept the incoming connection to port 80 from eth0 which connect to the Internet with the publich IP by the second rule. From the process path in the “iptables” part, the packet will also pass the FORWARD chains. We add the second rule in FORWARD chain to allow forwarding the packets to port 8080 of 192.168.1.2.

From systutorials and other manuals...

1
  • Thanks for the suggestions. Port forwarding is enabled, I'll check the others. – Mourndark Mar 4 '16 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.