I have running an Ubuntu 18.04 with 2 ethernet NICs. On both NICs I'm using DHCP. How can I prevent netplan from creating a default route to on both devices? I want one NIC routing to and the other one in a specific /24 subnet via a gateway. I know that I can add a route in the netplan config but it will always create the default route to

  • Welcome to Unix & Linux! :-) Go static on both adapters or static on at least one of the adapters. Going DHCP on both is a bad idea as you found out.
    – Fabby
    May 9, 2019 at 14:10
  • Network Manager has a specific option to ignore the default route on DHCP. No idea about netplan. Just telling some people thought about this issue, even for DHCP
    – A.B
    Jun 3, 2019 at 0:43

4 Answers 4


According to this answer, it should be possible with dhcp4-overrides, however that is not supported in Ubuntu as of 18.04. My workaround was to create a hook script in /etc/networkd-dispatcher/routable.d/ to remove the default route:


# Only remove the default route on the second interface, e.g. eth1
[ "$IFACE" != eth1 ] && exit 0

# delete the default route for this interface
ip route del default dev eth1

Make sure the file owner and group are root and that it is executable.

You can find out more about networkd-dispatcher here: https://gitlab.com/craftyguy/networkd-dispatcher


For more control of your NICs, go static on both adapters or static on at least one of the adapters.

This can be easily done in that specific range by reserving both IPs for their respective MAC addresses in their respective DHCP servers and then you will not have any of the limitations of DHCP and configure everything or part manually.

(E.G. If your corporate policy would require you to use a totally different IP range if using static, you can still use the aforementioned hybrid technology)

super@gitlab:~$ lsb_release -dc
Description:    Ubuntu 18.04.4 LTS
Codename:   bionic
super@gitlab:~$ cat /etc/netplan/50-cloud-init.yaml 
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
            dhcp4: false
                search: []
            dhcp4: true
                use-routes: false
              - to:
    version: 2
super@gitlab:~$ ip r
default via dev ens18 proto static via dev ens19 proto static dev ens19 proto kernel scope link src dev ens18 proto kernel scope link src 
  • 1
    Welcome to Unix.SE! Could you edit your answer to explain what it does? I take it the significant piece is use-routes: false in the DHCP4 overrides... Sep 23, 2020 at 20:40
  • It seems that the dhcp4-overrides: use-routes: false is indeed the useful part. It worked for me in Ubuntu 20.04
    – wojtow
    Sep 6, 2021 at 22:21

dhcp4-overrides doesn't work for me on ubuntu 20.04.

Try to create separate files for different interfaces, for example,

For the first interface that you want the default route to be added, let's say eth0:


  version: 2
      dhcp4: true

Then for the other one you want to avoid the default route, eth1, create another file:


  version: 2
  renderer: networkd
      dhcp4: true

Then run sudo netplan apply and check your routes with ip r

It appears that using networkd as the renderer it won't create the default route for you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .