2

I have 2 interfaces: eth0 and wlan0, each one connected to a different router. Their network specs are these:

eth0:
    ip: 192.168.1.7
    Gateway: 192.168.1.1
    Submask: 255.255.255.0

wlan0:
    ip: 192.168.2.21
    Gateway: 192.168.2.1
    Submask: 255.255.255.0

I've configured the routing this way:

ip route add table eth0 to 192.168.1.0/24 dev eth0 scope link
ip route add table eth0 default via 192.168.1.1 dev eth0
ip rule add from 192.168.1.7 table eth0

And the same for wlan0 using his values. So the routing output is:

ip rule
    0:      from all lookup local
    32764:  from 192.168.2.21 lookup wlan0
    32765:  from 192.168.1.7 lookup eth0
    32766:  from all lookup main
    32767:  from all lookup default

ip r s
    default via 192.168.1.1 dev eth0  proto static
    192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.7  metric 1
    192.168.2.0/24 dev wlan0  proto kernel  scope link  src 192.168.2.21  metric 9

ip r s table eth0
    default via 192.168.1.1 dev eth0
    192.168.1.0/24 dev eth0  scope link

ip r s table wlan0
    default via 192.168.2.1 dev wlan0
    192.168.2.0/24 dev wlan0  scope link

And also changed sysctl "net.ipv4.conf.all.rp_filter=0" and sysctl -w "net.ipv4.ip_forward=1". (Don't really think that ip_forward is needed but I've changed it just in case).

Now, the weird thing is that when I ping Google forcing interface wlan0 it says Destination Host Unreachable. The other interface works fine.

ping -I wlan0 google.es
    PING google.es (173.194.45.183) from 192.168.2.21 wlan0: 56(84) bytes of data.
    From 192.168.2.21 icmp_seq=1 Destination Host Unreachable
    From 192.168.2.21 icmp_seq=2 Destination Host Unreachable
    From 192.168.2.21 icmp_seq=3 Destination Host Unreachable
    From 192.168.2.21 icmp_seq=4 Destination Host Unreachable

ping -I eth0 google.es
    PING google.es (173.194.45.191) from 192.168.1.7 eth0: 56(84) bytes of data.
    64 bytes from mad06s09-in-f31.1e100.net (173.194.45.191): icmp_seq=1 ttl=56 time=21.5 ms
    64 bytes from mad06s09-in-f31.1e100.net (173.194.45.191): icmp_seq=2 ttl=55 time=21.7 ms
    64 bytes from mad06s09-in-f31.1e100.net (173.194.45.191): icmp_seq=3 ttl=56 time=24.6 ms
    64 bytes from mad06s09-in-f31.1e100.net (173.194.45.191): icmp_seq=4 ttl=55 time=31.1 ms

1 Answer 1

2

I am not sure how the source address determination is done in case of such a forced interface binding. If the source address is not taken from the device then the problem is that your ip rule selectors don't match so that the packet runs into the main routing table i.e.

default via 192.168.1.1 dev eth0  proto static

which doesn't work from wlan0.

I suggest you try this:

ip rule add from 192.168.1.7  table  eth0
ip rule add oif  eth0         table  eth0
ip rule add from 192.168.2.21 table wlan0
ip rule add oif  wlan0        table wlan0

and extend the

ip route add table eth0
ip route add table wlan0

commands by the src option.

2
  • Oh my god! This is working!!!! 3 days with this trying tons of different configurations and you come with this perfect solution. Can you, please, explain why this worked? I have lost so much time with this and want to learn something about it (don't really understand the 'source address determination' thing). Thank you again! Jan 4, 2015 at 22:19
  • Ok, just checked andoif is what does the trick. Thank you again! Jan 4, 2015 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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