Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Consider the following setup:

X@Y:~$ sudo ip link add link eth0 name eth0.3 type vlan id 3
X@Y:~$ sudo ip link add link eth0 name eth0.2 type vlan id 2
X@Y:~$ sudo ifconfig eth0.2 192.168.2.1/30
X@Y:~$ sudo ifconfig eth0.3 192.168.2.2/29
X@Y:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
...
192.168.2.0     0.0.0.0         255.255.255.252 U     0      0        0 eth0.2
192.168.2.0     0.0.0.0         255.255.255.248 U     0      0        0 eth0.3

As you can see, while they have overlapping subnets, both routes for eth0.2 and eth0.3 get installed. However, when I try this:

X@Y:~$ sudo ifconfig eth0.3 192.168.2.3/29
X@Y:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
...
192.168.2.0     0.0.0.0         255.255.255.252 U     0      0        0 eth0.2

You can see that the route for eth0.3 is not there. What is the major difference? The configured eth0.3 ip is the broadcast address of the subnet configured on eth0.2. Okay, yes this is messed up, but the interface comes online, the only thing that does not happen is adding the route to the route table. And actually, the route table doesn't even care about that broadcast address:

X@Y:~$ sudo route add -net 192.168.2.0/29 dev eth0.3
X@Y:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
...
192.168.2.0     0.0.0.0         255.255.255.252 U     0      0        0 eth0.2
192.168.2.0     0.0.0.0         255.255.255.248 U     0      0        0 eth0.3
X@Y:~$ sudo ip link del eth0.3
X@Y:~$ sudo ip link del eth0.2

Is there any way to get around this? Before you state that I found it out myself by adding the route afterwards: in my setup the actual ifconfig happens through a dhclient script that I cannot edit, so doing that route add would require hooking the dhclient, reading back the IP from somewhere and executing the route add which is quite tedious. I was hoping I could change this behaviour with some flags on the interface?

P.S. This is of course not a real network design, but is required for a testing setup.

share|improve this question

1 Answer 1

A active /30 route will always be preferred over any /29 route. So unless you had a /32 host route for 192.168.2.2 in place, the routing table would still send traffic to 192.168.2.2 to the /30 interface.

Its unclear if the 192.168.2.3 interface was ever installed, as the .3 is the broadcast for 192.168.2.0/30, and a packet sent to 192.168.2.3 has a special function: to be sent to all hosts on 192.168.2.0/30, not to be unicast to a less specific network on another interface.

If instead of a /30 and a /29, you were working with a /29 and a /28, you would be having a problem with the .7.

share|improve this answer

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.