No equivalent to ip route add X dev Y

Bug #1805038 reported by Michael Andersen
32
This bug affects 7 people
Affects Status Importance Assigned to Milestone
Netplan
Fix Released
Undecided
Unassigned

Bug Description

I need to find the netplan equivalent of the command

ip route add 10.96.0.0/24 dev ens3

Where the IP address of ens3 is 10.20.0.10/24. This is an unusual requirement, it's needed by kubernetes (see https://github.com/kubernetes/kubeadm/issues/102#issuecomment-291532883)

I have tried various attempts to capture this in netplan, and none of these even produce any routes at all (although netplan apply gives no errors)

I tried:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0f1:
      dhcp4: yes
    ens3:
      dhcp4: no
      dhcp6: no
      addresses: [10.20.0.10/16]
      routes:
      - to: 10.96.0.0/24
        via: 10.20.0.10

And I tried specifying

      routes:
      - to: 10.96.0.0/24
        via: 10.20.0.10
        scope: link
        on-link: true

I also tried

      routes:
      - to: 10.96.0.0/24
        via: 10.96.0.1
        scope: link
        on-link: true

Neither netplan apply nor rebooting actually produces any routes concerning 10.96.0.0/24 at all. The original ip route add command works well, what is the netplan equivalent of that?

Tags: fr-1077 sts
Revision history for this message
Richard Laager (rlaager) wrote :

Netplan doesn't support "dev", so this is effectively a feature request. I also need this feature. Currently, "via" is required. As "dev" is added, that restriction will need to be relaxed (e.g. that either "via" or "dev" is required).

Changed in netplan:
status: New → Confirmed
tags: added: sts
Lukas Märdian (slyon)
tags: added: fr-1077
Revision history for this message
Lukas Märdian (slyon) wrote (last edit ):

Hi Michael,

the "dev" part is enabled by default in netplan, as every route is defined within a network definition for a specific network interface.

But netplan assumes a default of type: "unicast" and scope: "global" for routes and such routes require a gateway ("via") setting. Maybe we should improve netplan's default here, to detect "scope: link" routes automatically...

The iproute2 example you showed above creates a "scope: link" route:

$ sudo ip route add 10.96.0.0/24 dev enp0s31f6
$ ip route
[...]
10.96.0.0/24 dev enp0s31f6 scope link

So in order to create the same effect via netplan, you should be able to use this stanza:

      routes:
      - to: 10.96.0.0/24
        scope: link

PS: I started drafting some improvements here: https://github.com/canonical/netplan/pull/248

Changed in netplan:
status: Confirmed → In Progress
Revision history for this message
Lukas Märdian (slyon) wrote :

Released in 0.104

Changed in netplan:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.