Ubuntu – How to stop netplan from binding a default gateway on every interface


I have a fresh install of ubuntu server 17.10, however the problem may affect previous versions, but this is the first time I have encountered this situation.

The server is running 2 separate network cards, one for internal local network communications (trusted), the other is a public (untrusted) connection to the internet with the ISP.

In the past, I have always configured the internal connection as static, and without a default gateway, as the external card would be provided via DHCP from my ISP (static lease).


  version: 2
  renderer: networkd
      dhcp4: no
      dhcp6: no
      addresses: [192.168.1.xx/24]
        addresses: [,]
      dhcp4: yes
      dhcp6: no

Now this worked fine as I did not provide a gateway4 line in the eth0 configuration so it bound the default gateway from the ISP and worked fine.

I have since decided I wanted to use static leases for the server(s) in my homelab, and have configured as such on the internal router. But when I set up the netplan config as dhcp for both devices, it adds the default gateway for both interfaces (which makes sense because both DHCP servers are providing a gateway).

> route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    100    0        0 eth0         173.xxx.xxx.1         UG    100    0        0 eth1
173.xxx.xxx.0   U     0      0        0 eth1
173.xxx.xxx.1 UH    100    0        0 eth1   U     0      0        0 eth0 UH    100    0        0 eth0

How can I setup netplan so the eth0 adapter (internal) to disregard the default gateway provided by the DHCP server (without removing the gateway on the DHCP server itself as other machines still need a default gateway).

Best Answer

Netplan v0.90 introduces a new set of options: dhcp4-overrides (pull request).

So, if your version of the netplan.io package is new enough (see available versions here), you can use this:

      dhcp4: yes
        use-routes: false
Related Question