Meaning of prefix length with ip addr add noprefixroute

When assigning an ip address to a network interface with ip addr add noprefixroute, what effect will the specified prefix length have? When noprefixroute is not used, the prefix length is used to automatically create and delete a route for the network prefix of the added address. Does it have any function other than that?

For example, what is the difference between

ip addr add noprefixroute 10.137.0.36/16 dev eth0

and

ip addr add noprefixroute 10.137.0.36/32 dev eth0

?

Asked By: p0ny

||

Indeed there doesn’t appear to be much useful difference, but there’s at least one: the way a secondary address is handled won’t change, whether a route is added or not.

When a 2nd address is added to the same interface as an other address with the same netmask within the same network, it’s classified as a secondary address. When the first address (primary, without the secondary property) is removed, all other matching addresses in the same IP LAN, all secondaries, are also removed.

Example:

  • from scratch:

    # ip addr flush dev eth0
    
  • add the main address (the first):

    # ip addr add noprefixroute 10.137.0.36/16 dev eth0
    
  • add an other address within the same IP LAN, using the same netmask

    # ip addr add noprefixroute 10.137.0.42/16 dev eth0
    
  • check current state

    # ip route
    # ip addr show dev eth0
    2: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
        link/ether 0e:00:00:74:02:fd brd ff:ff:ff:ff:ff:ff link-netnsid 0
        inet 10.137.0.36/16 scope global noprefixroute eth0
           valid_lft forever preferred_lft forever
        inet 10.137.0.42/16 scope global secondary noprefixroute eth0
           valid_lft forever preferred_lft forever
    
  • remove primary (first) and witness 2nd gone too

    # ip addr del 10.137.0.36/16 dev eth0
    # ip addr show dev eth0
    2: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
        link/ether 0e:00:00:74:02:fd brd ff:ff:ff:ff:ff:ff link-netnsid 0
    

This wouldn’t have happened with two /32 because they would both be considered primary addresses (Using /32 they are not part of the same IP LAN). By the way, there’s a parameter to promote a secondary as primary instead of deleting all secondaries: promote_secondaries.

Conclusion: noprefixroute affects creation of routes, but not other properties linked to addresses.

I don’t know if there are more visible differences. Maybe something can be found with ARP when settings such as arp_ignore or arp_announce are changed from their permissive default: unlike arp_filter their description is about addresses, not routes.

Answered By: A.B
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.