Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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...

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

routing decisions are based on destination addresses. if you want do route traffic based on the source address you need do configure policy based routing. have a look at:

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

i answered these similarly 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

share|improve this answer
    
It is working. But when I watch netstat -i, it looks like both interfaces are receiving packets. –  Maarten Jan 26 '13 at 16:52
    
it is working now. I had to remove the default route from the main route table. –  Maarten Jan 26 '13 at 17:37
add comment

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.