My embedded hardware running Ubuntu 16.04LTS has two NICs, eth0 and eth1. In production, eth0 is connected and should use as the gateway for addresses outside the /24 subnet. For diagnostics or field upgrades, I want to be able to connect eth1 to my Windows PC and use Windows 10 Internet Connection Sharing, which by default provides a gateway of
Because there is no wifi and I'm trying to keep it simple, I've uninstalled the Ubuntu NetworkManager and I'm just using /etc/network/interfaces.

The modest goal is for whichever interface is active to set the gateway, and a bonus would be able to set one as a higher priority with a metric command, but I could live without that. I was hoping to be able to avoid setting the routing table with specific commands.

The /etc/network/interfaces file of my dreams looks like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
  metric 100

auto eth1
iface eth1 inet static
  metric 50

plus whatever is needed to make it actually work, since it doesn't currently meet expectations. At the moment it works fine when eth0 is plugged in but when only eth1 is connected, it can see the local subnet but it does not route anything through the gateway.

I feel like this is not very complicated, and yet I can't seem to find a simple solution in similar postings

  • 1
    netmask would be an invalid mask. – Ron Maupin May 6 at 22:34
  • The auth devicename will bring the interface up always. You may want to try setting allow-hotplug devicename, which may only bring up the interface when there is a connection (depends on hardware). – Zoredache May 6 at 22:36
  • thanks, I fixed the netmask, will try allow-hotplug and report back – WiringHarness May 6 at 22:38
  • Well @Zoredache the allow-hotplug was an improvement but the gateway still does not change. Right now the gateway is always no matter which interface is connected. – WiringHarness May 6 at 22:52

You've got your metric lines reversed. Lower numbers have higher priority.

Also you could just use DHCP for eth1, as Windows ICS has a built in DHCP server.

  • The metric was on purpose so that it would use the ICS gateway whenever it is connected. Also, I can't get DHCP to work at all, although I've seen it work on other versions of Windows. – WiringHarness May 7 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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