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?
To temporarily change the default route you can use an ip command like this:
$ sudo ip route change default via 192.168.1.1 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 gateway 192.168.1.1 […]
Using DHCP to configure networking you have to adjust another file instead. Add the supersede statement in
supersede routers 192.168.1.1;
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=192.168.0.16/24 static routers=192.168.0.1 static domain_name_servers=127.0.0.1
to get the following
#interface wlp3s0 # static ip_address=192.168.0.16/24 # static routers=192.168.0.1 # static domain_name_servers=127.0.0.1
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 18.104.22.168. 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.