Ubuntu – How to add a route that is “on the link”, directly connected to the interface even if the IPs are not the same

17.10netplannetworkingserver

We're working on an Ubuntu 17.10 linux and we would have to use Netplan for network configuration. We have a /run/systemd/network/*.network file which fit what we need, but we want to "translate" it in a Netplan config file.

[Match]
Name=ens18

[Network]
Address=<guestIP>/32
Gateway=62.210.0.1
DHCP = none
DNS=8.8.8.8 8.8.4.4

[Route]
Destination=62.210.0.1/32
Scope = link

We want to transpose this in the /etc/netplan/*.yaml file but we don't find how to do those two things:
– The scope = link doesn't seem to have a direct translation in the .yaml file. We're using it because we're working into a VM;
– The via line is required in the .yaml file when configuring route but 0.0.0.0 doesn't work.

With our configuration via the .network file, here is what route -n returns:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         62.210.0.1      0.0.0.0         UG    0      0        0 ens18
62.210.0.1      0.0.0.0         255.255.255.255 UH    0      0        0 ens18

So how to translate our two problematic lines in the Netplan config file?

Best Answer

Starting with netplan 0.34 (now in Ubuntu 18.04), you can add "scope: link" to your route in netplan config, with something like this:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      [...]
      gateway4: 62.210.0.1
      routes:
        - to: 62.210.0.1/32
          via: 62.210.0.1
          scope: link
Related Question