I have a multihomed host with 2 Ethernet interfaces and a usb-connected cell modem. The Ethernet interfaces are configured in a typical way on the main routing table, with only one default route assigned to one of them.
[/]# ip route show table main
default via 192.168.4.1 dev eth0 metric 50
192.168.2.0/24 dev eth1 scope link src 192.168.2.10
192.168.4.0/22 dev eth0 scope link src 192.168.4.73
There is another default route assigned to the cell interface on a separate "usbcell" routing table.
[/]# ip route show table usbcell
default via 10.26.128.2 dev usbcell src 10.26.128.1
An IP rule directs all packets marked with value 0x100 to use the usbcell routing table. These packets are marked at the socket level within an application. We also add source based routing rule to prevent reverse path filtering from dropping usbcell traffic.
[/]# ip rule
0: from all lookup local
97: from 10.26.128.1 lookup usbcell
100: from all fwmark 0x100 lookup usbcell
32766: from all lookup main
32767: from all lookup default
The Cell interface has an IP, netmask and gateway provided dynamically by the modem hardware. This subnet is not owned by the carrier or us, so I would like to prevent collisions with any other networks connected to the Ethernet ports. This should be easy since the cell interface is on a separate routing table. But, unfortunately, whenever the cell interface is brought up via ifup, a local route to the interface is added to the main table. This routes all packets bound for that subnet to the cell interface instead of just the marked ones. If I remove the local route, it works as expected.
Main table when usbcell is up:
[/]# ip route show table main
default via 192.168.4.1 dev eth0 metric 50
10.26.128.0/17 dev usbcell scope link src 10.26.128.1 ## How do I prevent this? ##
192.168.2.0/24 dev eth1 scope link src 192.168.2.10
192.168.4.0/22 dev eth0 scope link src 192.168.4.73
Is there a way of preventing this local route from being added to the main table when the usbcell interface is brought up?
10.26.128.0/17 dev usbcell scope link src 10.26.128.1
In this example, I want unmarked packets bound for the subnet 10.26.128.0/17 to be routed out the main table default route (to eth0).
ip
commands which delete the route in apost-up
option below theiface usbcell ...
stanza in/etc/network/interfaces
(iiuc, you're usingifupdown
; if that's not right, give more details about your system) Instead of not adding a default route, add one with a high metric e.g. withpost-up r=$(ip route show to default dev $IFACE); ip route del $r; ip route add $r metric 800
(themetric
option described in the manpage doesn't always work right). IIRC, NetworkManager does this by default.10.26.128.0/17 dev usbcell scope link
, basically you are makingusbcell
unusable. If you do want this, you could also bring the interface down. You didn't explain what you needusbcell
, but a possible solution to prevent conflict with theeth
interfaces is to put one party (or both) into a network namespace.metric
option in theiface
stanza, with a large value. However, last time I had used it, I had problems with it only being applied to a single interface, if two interfaces happened to be on the same network. Or something like that, and some other problems I forgot about ;-)