Set Network Interface Metric

Thomas Hunter II picture Thomas Hunter II · May 15, 2012 · Viewed 60.1k times · Source

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

Answer

AlexT picture AlexT · Jun 6, 2012

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 10.10.0.1 netmask 0.0.0.0 dev wlan0 metric 1
sudo route del -net default gw 10.10.0.1 netmask 0.0.0.0 dev wlan0 metric 0