This question already has an answer here:

When I add 2 interfaces (eth0 LAN, eth1 WAN) with static IPs (or maybe also with DHCP), Ubuntu 18.04 Server is adding 2 default gateways. Thats not the goal.

How can I define only 1 default gateway?

File: /etc/netplan/01-netcfg.yaml

  version: 2
  renderer: networkd
        search: [mydomain.internal]
        addresses: [,]
        addresses: [195.50.xxx.xxx,195.50.xxx.xxx]

ip route shows:

user@server:~$ ip route
default via dev eth1 proto static
default via dev eth0 proto static dev eth0 proto kernel scope link src dev eth1 proto kernel scope link src

2 default GWs......

In my case, the default GW from eth1 is the one and only I need.

marked as duplicate by zwets, karel, Thomas, Eric Carvalho, waltinator Aug 7 '18 at 15:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Just remove the gateway configuration from the eth0 interface.

Omit the line which says gateway4:

You will still be able to reach hosts in the 172.16.x.y subnet through eth0, since it's directly connected there.

If you need to access other hosts in that network (for example, an intranet with private addresses in the RFC1918 ranges), then just add static routes to access those networks using the gateway. See this reference for routing in Netplan, which should help you add static routes.

If you get your IPs through DHCP, it should be mostly the same... But then you need the DHCP server that hands you an IP on eth0 not to set any gateways... There doesn't seem to be a good way in Netplan to disable a gateway you receive from DHCP. (Though networkd can do that, see this comment on another answer for an attempt to address that.)

Not the answer you're looking for? Browse other questions tagged or ask your own question.