Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 9 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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