19

I have two interfaces eth1 and eth0. I want all traffic on eth0to be forwarded to eth1. I created an iptable rule like this:

iptables -A FORWARD -s 0/0 -i eth0 -p tcp -o eth1 -j ACCEPT

But this doesn't work. Is this the correct way of doing this?

1 Answer 1

32

If you haven't already enabled forwarding in the kernel, do so.

  • Open /etc/sysctl.conf and uncomment net.ipv4.ip_forward = 1

  • Then execute $ sudo sysctl -p

Add the following rules to iptables

sudo iptables -t nat -A POSTROUTING --out-interface eth1 -j MASQUERADE  
sudo iptables -A FORWARD --in-interface eth0 -j ACCEPT

All of the forwarded traffic will traverse the FORWARD chain. To filter packets you'll now have to create rules on that chain specifying which interface is incoming/outgoing instead of using the INPUT/OUTPUT chains.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .