I'm able change my network routing metrics with ifmetric, for example ifmetric enp0s3 1.

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    1      0        0 enp0s3         UG    100    0        0 enp0s8

When I reboot though, the metric for enp0s3 reverts to 101. How can I make this change permanent or have it set automatically at boot time?


The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:


# Change the metric of the default route only on interface enp0s3


if [ "$IF" = "enp0s3" ]
        case "$STATUS" in
                ip route del default dev $IF
                ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC

This way, your customization will not be overwritten upon each update. In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.

You can find documentation here.

|improve this answer|||||
  • That's assuming that we're using Network Manager in Debian, which is still not necessarily the case (As in my case, for instance; I dropped it to avoid a systemd-as-init dependency that was causing boot failures at random). Other than that this is still a good answer for most (but definitely not all) Debian users. It works fine on my other system which still uses Network Manager. – Wyatt8740 yesterday

If you are using NetworkManager, the proper way to change the metric for the default route is to modify the connection associated with interface enp0s3 in this way:

nmcli connection modify <connection-name> ipv4.route-metric 1

and then re-activate the connection:

nmcli connection up <connection-name>

You can find the value for <connection-name> in the output of nmcli connection.

|improve this answer|||||
  • This does not really answer the question, because it does not do it at boot time, automatically. – MariusMatutiae 23 hours ago

You should be able to make it permanent in /etc/dhcpd.conf where you can set an interface metric like this.

interface enp0s3;
metric 1;
|improve this answer|||||
  • Um, I don't think so. What is the os? Also try and see if this exists /etc/conf.d/dhcpcd – Pythonic Feb 14 '17 at 17:58
  • tried creating this file with your settings - it did not work. Ubuntu 16.10. Thanks though. – marathon Feb 15 '17 at 4:24
  • didn't work with me either – Guerlando OCs Jul 4 '18 at 17:52

The easiest and right way to do this is by editing /etc/network/interfaces.

Here is a simple example of /etc/network/interfaces:

auto lo eth0
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet dhcp
    metric 700

Restart networking using service networking restart for the changes to take place.

Ref: Section 5.7.2. The ifmetric package of Debian Manual

The following sets the eth0 interface to be preferred over the wlan0 interface.

Install the ifmetric package.

Add an option line with "metric 0" just below the "iface eth0 inet dhcp" line in "/etc/network/interfaces".

Add an option line with "metric 1" just below the "iface wlan0 inet dhcp" line in "/etc/network/interfaces".

Extra Note:

  • auto <interface1> <interface2> starts interfaces on start of the system.
  • allow-hotplug <interface> starts the interface on hotplug event.
|improve this answer|||||

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.