7

I have a machine with a built-in NIC (eth0), which serves as a DHCP server for a Raspberry Pi. I also have a USB 3G modem, which shows up as ethernet device eth1. eth0 has the static ip 192.168.100.1 in /etc/network/interfaces. When I connect the Pi to the server, /var/log/syslog shows

NetworkManager[2366]: <info> Policy set 'Ifupdown (eth0)' (eth0) as default for IPv4 routing and DNS.

and after, ip route show gives

default via 192.168.1.100 dev eth0  proto static

I then need to manually

ip route delete default
ip route add default via 192.168.1.1

to get it to connect to the internet via the 3G modem again. I am using CrunchBang Linux, based on Debian 7 wheezy, on the server, and the latest Raspbian on the Pi.

How can I choose the default pathway for NetworkManager to prefer?

Edit: here's my /etc/network/interfaces:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

allow-hotplug eth0
auto eth0
iface eth0 inet static
    address 192.168.100.1
    netmask 255.255.255.0

allow-hotplug eth1
auto eth1
iface eth1 inet dhcp

Note that I've changed /etc/NetworkManager/NetworkManager.conf to have

[ifupdown]
managed=true

because I want to be able to disconnect eth1, the 3G Modem, using nm-applet. Here's /etc/NetworkManager/NetworkManager.conf:

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=true
5
  • Don't you have two default routes at some point? May 13 '15 at 23:01
  • ip route show only ever shows one default route. What I'd like to know is, where does NetworkManager define its preferred route - which keeps overriding my manual setting.
    – appas
    May 13 '15 at 23:07
  • In connections. It's either in gui, accessible through nmcli, or under /etc/NetworkManager/system-connections/ May 13 '15 at 23:12
  • I'm not sure what you're asking. In the nm-applet GUI, I have entries for both wired connections, with eth0 listed as ifupdown (eth0). The problem is that when connected, this connection will cause nm-applet to notify "You are now connected to 'ifupdown (eth0)' " and the "Policy set" message to appear in syslog.
    – appas
    May 13 '15 at 23:23
  • what is the content of /etc/NetworkManager/NetworkManager.conf ? May 14 '15 at 0:00
9
  • If using GUI, try checking the "Use only for resources on this connection" checkbox.
  • If using the config files (like you are :) ), in the [ipv4] section add never-default=true .
  • If using commandline tools, run sudo nmcli con mod "connection name" ipv4.never-default yes

This way you will be able to delete the default route going in the tunnel & add your own.

6
  • Thanks a lot! editing config helped me to make internet open on my wifi, ifmetric did not help. ifmetric not working with network manager? Mar 17 '18 at 6:23
  • That question is a bit offtopic, but it also seems like coming from a time machine. Looks like the latest version of ifmetric came out in 2004...
    – Richlv
    Mar 18 '18 at 17:48
  • :-) I've just recently started to use Linux on a regular basis, now trying things found by internet search, some are still valid, some are not... Does there any way to insert line to file in specific section by bash script? I want to write a script to configure my Linux after install automatically next time to suit my needs. Mar 22 '18 at 18:01
  • This is getting completely offtopic now :) I'd suggest checking out corresponding manpages and then IRC channels of bash and sed.
    – Richlv
    Mar 22 '18 at 21:51
  • You can also do it via cli: sudo nmcli con mod "connection name" ipv4.never-default yes
    – keeshux
    Jul 27 '20 at 17:32
7

I'm 4 years late, but I've just spent 12 hours discovering and then fixing this issue. Similar situation here: ARM based Jetson Nano running Linux 4 Tegra kernel and Ubuntu 18.04 OS, with the Ethernet port (eth0) used for a local network and a USB Cellular dongle (eth1) used for Internet.

Symptoms are similar - once the Ethernet cable is plugged in the interface is brought up, then 3 minutes later I get:

NetworkManager[3773]: [1562908622.2587] policy: set 'Wired connection 1' (eth0) as default for IPv4 routing and DNS

in syslog and the internet connection is dropped.

NetworkManager works in mysterious ways that are difficult to program around - much better suited to having a user sitting in front that can reset things if necessary. I don't have that luxury, so had to make it work.

Ultimately what worked was to set the ipv4.route-metric lower (higher priority) on eth1. Check the output of route -n to see what the current metrics are. Ignore the additional 20000 on some routes - this is NetworkManager trying to de-prioritise routes that don't have Internet connectivity, but it's screwy.

So say eth0 has a metric of 100. Prioritise your eth1 interface with:

sudo nmcli con mod "Wired connection 2" ipv4.route-metric 99

And reboot.

Now to save you 10 hours of troubleshooting - note that the route metric is independent of the DNS priority! So if you still have connectivity issues, make sure it's not a DNS resolution issue (eg. your DHCP server is providing a dummy resolution service). If it is, then increase the ipv4.dns-priority of your eth0 connection to make it lower priority, and/or make sure the ipv4.dns-search of your eth1 is set to "~" to make it the go-to option.

1
  • Really helpful I've been looking for this solution for a few years as well - really nice to have. In my case I have one wired broadband and one 5G backup via RJ45. This enables failover as opposed to the accepted option which will never use the secondary connection. You'd think this should be more obvious in the nm config apps. Also when restarting NetworkManager after adjusting this I encountered a NM bug where it fails to manage the interface with old priority. Required a restart in the end as whole network stack was hosed.
    – BoeroBoy
    Mar 8 '21 at 10:33
1

Network manager will always override your settings, You must edit:

vi /etc/network/interfaces

Find the eth0 and set:

gateway 192.168.1.1

Re start network service:

/etc/init.d/networking restart
2
  • 1
    I did this, but as soon as I connect interface eth0, I get the NetworkManager[2366]: <info> Policy set 'Ifupdown (eth0)' (eth0) as default for IPv4 routing and DNS and ip route show will show default via 192.168.1.100 dev eth0 proto static.
    – appas
    May 13 '15 at 23:39
  • I'm confused, if manager will overwrite, why edit that default old location, not manager config files? On my Linux interfaces file contains info only about lo. Mar 22 '18 at 18:05

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.