Use this connection only for resources on its network

I like NetworkManager, it has good functionality, reliability, configuration. There’s good GUI and CLI tools for it. When using the “Advanced Network Configuration” GUI (nm-connection-editor) there’s an option within the routes section (IPv4 Settings → Routes) that sets the ipv4.never-default config. “Use this connection only for resources on its network”

My understanding is when this option is on, it will only use the route when accessing hosts within the same subnet. However, in my tests this is not working and I would like some help to achieve my needs.

I have a system connected to two networks, one has access to the Internet and the other does not. Two NICs, two Ethernet cables, two routers. Let’s say 192.168.1.x and 192.168.2.x. I need to be able to access hosts on the second network but I want everything else to default to the first. What’s happening is when I try to access Internet, it’s attempting to route through the network that doesn’t have Internet access.

My temporary fix is to just manually disconnect the Internet access NIC and reconnect it. I have tried changing the autoconnect order but it doesn’t seem to make a difference. Though manually it appears to use the most recently connected network as the default route.

If you know how to do achieve this using something other than NetworkManager, such as systemd-networkd. I’m open for suggestions.

Post the output of IP route with both network cables connected

Very strange inconsistent behavior going on here and I suspect it has something to do with the PCIe -> USB 3 -> Gigabit Ethernet adapter. When I first set this up it was not working and I tried everything from systemctl restart NetworkManager to rebooting multiple times. Though the temporary fix I mentioned did make it work. Just now after reading your post I checked ip route output to see it having both networks listed with default via and the temporary fix no longer working. I just rebooted the system and now it’s working as intended with only the main network as default. Thanks for your time anyways. I would still be interested in other ways to achieve this without NetworkManager if you don’t mind.

This thread looks interesting if you want to dig deeper and still use network manager

In the old non GUI times, each distro had a flag to include in the DHCP config of an interface to ignore the default gateway …