I've been trying to configure IPTABLES in my server so I can share the internet from the server with another machine. The server IP is (eth0), the connection is coming from (eth0:2), the client is (eth1 in the machine). I've tried using the commands from


with the correct changes, but I can't make it work, the client can ping (where the internet is coming from), but it can't access the internet at all.


eth0 eth0:2 Currently has connection with both the client and the internet



eth1 Can ping both the router and the server


edit /etc/sysctl.conf and uncomment:

# net.ipv4.ip_forward=1

And the iptables part should look something like below, where eth0 is internet and eth1 is LAN:

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

iptables -A FORWARD -i eth1 -o eth0 -m state -–state RELATED,ESTABLISHED -j ACCEPT

iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

If you have 2 physical network interfaces in server then it should work, you cant use your server as internet gateway if it only has 1 physical interface

  • Yes, I only have one physical interface, now I'm aware of the problem, thanks. – Luck20 Jun 22 '16 at 20:20

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.