No equivalent to ip route add X dev Y

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

Bug Description

I need to find the netplan equivalent of the command

ip route add dev ens3

Where the IP address of ens3 is This is an unusual requirement, it's needed by kubernetes (see

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:

  version: 2
  renderer: networkd
      dhcp4: yes
      dhcp4: no
      dhcp6: no
      addresses: []
      - to:

And I tried specifying

      - to:
        scope: link
        on-link: true

I also tried

      - to:
        scope: link
        on-link: true

Neither netplan apply nor rebooting actually produces any routes concerning 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 dev enp0s31f6
$ ip route
[...] dev enp0s31f6 scope link

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

      - to:
        scope: link

PS: I started drafting some improvements here:

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.