Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

1 Answer 1

up vote 2 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

 
discard

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.