Linux – Set Network Interface Metric


What is the proper way to set network interface metrics these days?

I'm looking for command line ways for doing this. I'm currently using Arch Linux, but a distro-agnostic method would be preferred.

Here is my failed attempt:

$ sudo ifconfig wlan0 metric 1
SIOCSIFMETRIC: Operation not supported

Best Solution

As stated in man ifconfig, metric is not a supported option for the ifconfig command on Linux systems, because when the ifconfig command is processed it doesn't create a routing table entry.

   metric N
          This parameter sets the interface metric. It is not available under GNU/Linux.

To answer your question, you'd have to use the route command, to add the route with the desired metric and delete the old entry. For example:

sudo route add -net default gw netmask dev wlan0 metric 1
sudo route del -net default gw netmask dev wlan0 metric 0
Related Question