My embedded hardware running Ubuntu 16.04LTS has two NICs, eth0 and eth1. In production, eth0 is connected and should use 192.168.0.1 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 192.168.137.1.
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 address 192.168.0.2 netmask 255.255.255.0 gateway 192.168.0.1 metric 100 dns-nameservers 22.214.171.124 auto eth1 iface eth1 inet static address 192.168.137.2 netmask 255.255.255.0 gateway 192.168.137.1 metric 50 dns-nameservers 126.96.36.199
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
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.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.