I am using 3 ethernet interfaces on Ubuntu but when I restart, the default gateway is changing to a different interface. Each time I boot I have to change default gateway back to the eth1 by deleting the default gateway and adding it back with eth1. How can I fix this problem?

  • Have you configured it manually using the /etc/network/interfaces file, or a with software like Network Manager or wicd?
    – Lekensteyn
    Mar 23, 2011 at 12:56
  • 1
    "Gateway" is not equal to "route". A gateway is specific to an interface where an route says which interface should be used.
    – Lekensteyn
    Jun 2, 2011 at 19:24
  • The gateway is usually an interface on a remote device which the local node is relying on for routing decisions. A route statement itself can refer to a local interface or not, but the routing destination has to be discoverable from a recursive lookup, connected interface, or default route. A default route or default gateway is the 'gateway of last resort' -- which will be used in the absence of a more specific route being available.
    – belacqua
    Oct 29, 2011 at 22:14
  • Can you provide your routing table and list of interface, and other any relevant network configuration you've done?
    – belacqua
    Oct 29, 2011 at 22:17

3 Answers 3


To temporarily change the default route you can use an ip command like this:

$ sudo ip route change default via dev eth0

If you have a static ip configuration in /etc/network/interfaces you can add a gateway statement to make this permanent.

iface eth0 inet static

Using DHCP to configure networking you have to adjust another file instead. Add the supersede statement in /etc/dhcp/dhclient.conf.

supersede routers;
  • 1
    Scriptable version (should be a space between the quotation marks): echo supersede routers $(ip route | grep default | cut -f3 -d" ")\; | sudo tee --append /etc/dhcp/dhclient.conf
    – colan
    Jan 10, 2017 at 22:15
  • What if I have multiple interfaces? Shouldn't they all have a 'gateway' for each interface? But what affects the example ''default via dev eth6" output of ip route command? It lists a specific interface, right?
    – JohnyTex
    Sep 27, 2018 at 9:19

Open the file /etc/network/interfaces

find desired interface and add following:

gateway 192.x.x.x

Restart network:

sudo /etc/init.d/networking restart
  • 17
    What if the desired interface is configured via DHCP and I don't know the gateway address it will assign? Aug 31, 2012 at 10:40

I had the same issue for my wifi interface wlp3s0 on Ubuntu 18.04. It was affecting my ability to connect to Android tethering and router outside home. The way to solve the issue for me was to comment in file /etc/dhcpcd.conf the following:

interface wlp3s0
        static ip_address=
        static routers=
        static domain_name_servers=

to get the following

#interface wlp3s0
#        static ip_address=
#        static routers=
#        static domain_name_servers=

Then, I've disconnected from my current network and reconnected an tried route -n or nmcli to see changes

You can also remove the same lines when you are sure it works for you.

Because of these lines, the NetworkManager was always adding a default route with a wrong gateway, in particular when I was not on my home network. I was getting "Destination Host Unreachable" when I was doing a ping Hardcoding a gateway in /etc/network/interfaces was not a viable solution as I connect a lot to public wifis (so, never the same wifi router or gateway) and normally DHCP should work "out of the box" IMHO.

PS: I've never edited manually /etc/dhcpcd.conf so I don't know why the file /etc/dhcpcd.conf did contain these lines.


You must log in to answer this question.

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