Ubuntu – How to toggle NetworkManager’s “Use this connection only for resources on its network” option via command line

17.04bashnetwork-managernmclirouting

At my work we have some test machines that we run scripts on via ssh. During the test we want to only have the machines access the local network through their Ethernet connection, but then would like to have them be able to access the Internet through the same interface for cleanup and data transmission after.

We can do this by going to each machine and toggling the "Use this connection only for resources on its network" option in the network manager > IPv4 options > routes menu, but it would be a lot more convenient to be able to add this into our test script.

I can find some similar questions that have to do with VPN connections, but I want to make sure I handle the routing correctly for the regular Ethernet interface. Thanks for any help.

Best Answer

You can use nmcli to do it, the key is ipv4.never-default:

nmcli connection modify enp3s0 ipv4.never-default true
  • change enp3s0 with your own connection name.
  • use false or true to toggle between this config.
Related Question