1

This example from netplan examples

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
     addresses:
       - 9.0.0.9/24
       - 10.0.0.10/24
       - 11.0.0.11/24
     #gateway4:    # unset, since we configure routes below
     routes:
       - to: 0.0.0.0/0
         via: 9.0.0.1
         metric: 100
       - to: 0.0.0.0/0
         via: 10.0.0.1
         metric: 100
       - to: 0.0.0.0/0
         via: 11.0.0.1
         metric: 100

Why do the routes part of the interface configuration?
Aren't routes global?
These are 2 different things, routes and interfaces.

  • As an aside unrelated to your question, the configuration you list is probably not going to work very well. You have three 0.0.0.0/0 routes, all via different gateways and all with the same metric. I assume you are doing this because you want to load balance between the three gateways. But that is not going to work very well, because the kernel has no reliable way of knowing what traffic needs to be associated with a given source address, so remote servers will randomly become confused when traffic comes from a different address than was used for earlier related traffic. – slangasek Apr 29 at 14:40
1

Routes do have an associated interface in the Linux routing table; you can see this in the output of ip route show in the dev column on your system. This information both lets the kernel know which interface the traffic needs to be sent out without having to calculate the route dependencies for each packet, and lets the kernel do the right thing with routing when a given interface is in 'down' state.

From a netplan perspective, the association between routes and devices is important because devices will not come up all at the same time, and the system should only attempt to add the routes to the kernel when the route to the corresponding gateway is available.

| improve this answer | |
2

It's not uncommon for a route to be specific to an interface, however, they are usually global.

For example, if I have a VPN interface, I will probably want to route all the subnets at the other end of the VPN over that link. It's likely that these are private/reserved subnets, which means they will only be available when the VPN is active, so it wouldn't make sense to have them in the route table at all times, although it will probably still work.

In the example you have provided, there are multiple default routes, probably for redundancy.

Probably the most important rule to understand in routing is the "most specific route first" rule, which means that if you are trying to access 10.0.0.1, it will traverse a route of 10.0.0.0/25 before it will traverse a route of 10.0.0.0/24, which will obviously go before 0.0.0.0/0.

| improve this answer | |

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.