1

I have 2 internet connections on my network. My router is running Debian. eth0 is my network (192.168.0.0/16). 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 192.168.2.0/24 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
10.0.4.0        0.0.0.0         255.255.255.0   U     0      0        0 eth2
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth1
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         172.16.1.50     0.0.0.0         UG    0      0        0 eth1
0.0.0.0         10.0.4.2        0.0.0.0         UG    0      0        0 eth2
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth0

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

1 Answer 1

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:

http://www.linuxhorizon.ro/iproute2.html

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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