I have 2 internet connections on my network. My router is running Debian. eth0 is my network ( eth1 and eth2 are connected to 2 different internet providers (with dynamic IP).

Here is a small drawing of my configuration

PC1 ---|                  |-eth1- DynIP provider 1
PC2 ---|-eth0- Router --- |
PCn ---|                  |-eth2- DynIP provider 2

I'm trying to configure it as follow: I want all packets by default to go via eth1. All packets coming from a PC having address to go via eth2.

After looking for a while and posting on other forums I already have the following (in my rc.local file):

echo "1" > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE
iptables -A FORWARD -i eth1 -j ACCEPT
iptables -A FORWARD -i eth2 -j ACCEPT

with route table:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 eth2     U     0      0        0 eth1     U     0      0        0 eth0         UG    0      0        0 eth1         UG    0      0        0 eth2         UG    0      0        0 eth0

I tried to play with route and ip route but I cannot find it to work...

1 Answer 1


Routing decisions are based on destination addresses. If you want to route traffic based on the source address you need to configure policy-based routing. Have a look at:


I answered these similar questions a few weeks ago:

How can I route different traffic over different interfaces (routes) by protocol?

Using iptables to forward traffic destined for specific ip via specific interface

  • It is working. But when I watch netstat -i, it looks like both interfaces are receiving packets.
    – Maarten
    Commented Jan 26, 2013 at 16:52
  • it is working now. I had to remove the default route from the main route table.
    – Maarten
    Commented Jan 26, 2013 at 17:37

You must log in to answer this question.

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