Forwarding ports with iptables not working?
Try adding -i eth0
to your PREROUTING
entry and -o eth0
to your POSTROUTING
entry and executing sudo iptables -A FORWARD -i eth1 -j ACCEPT
Related videos on Youtube
Comments
-
James T over 1 year
I have an ubuntu server (14.04.1) which is asking as a router for my network. It has an internet facing interface, eth0, and a second interface, eth1, for connecting to my 10.0.0.0 network.
I am attempting to forward TCP traffic directed to eth0 (for this example, lets say its IP is 118.94.79.113) to eth1 with an address of 10.0.0.1 for port 27016
I have attempted the following commands in sequence:
sudo echo "1" > /proc/sys/net/ipv4/ip_forward
sudo sysctl net.ipv4.ip_forward=1
sudo iptables -t nat -A PREROUTING -p tcp --dport 27016 -j DNAT --to-destination 10.0.0.104:27016
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
but this doesnt seem to work at all, i cannot connect to 118.94.79.113:27016 to access the application running on 10.0.0.104:27016. Is it to do with it being across two interfaces or what?
-
James T over 9 yearsjust gave this a shot, postrouting cannot have an interface but other than that both other commands worked, still not able to access 10.0.0.104:27016 via 118.94.79.113:27016
-
Ben over 9 yearsMy mistake.
POSTROUTING
should have been-o eth0
-
James T over 9 yearsGiven that a shot, still no luck.. odd... EDIT: just noticed the protocol I'm trying to pass is UDP, DUH! ill edit the rules and come back with whether it worked or not.
-
James T over 9 yearsYep that worked...