# Changing the metric of an interface.

## bunkacid

Hi,

I've been stuck on an issue for several weeks now, that is bugging th crap out of me.  I've come across an issue when attempting to change the metric of an interface on my laptop.  Searching through the gentoo network configuration files, there isn't anywhere to change the metric of an interface.  I've also searched google, and have so far come up with no reason or answer as to why it isn't working.

```

pmobilex px # ifconfig ath0 metric 2

SIOCSIFMETRIC: Operation not supported

pmobilex px # ifconfig eth0 metric 2

SIOCSIFMETRIC: Operation not supported

```

I use both interfaces depending on what I am doing, but mostly use the ethernet interface when transfering large files.  Currently whenever I plug in the ethernet, I have to down the ath0 interface.

Before I changed over to Gentoo, I was a Debian user, and it was possible to change the metric.  Is there a kernel patch that is affecting this?

Any help would be greatly apprieciated

----------

## moocha

Changing the metric via ifconfig is fundamentally flawed in post-2.2 kernels. Use the ip tool from the iproute2 package. 

```
ip route add 1.2.3.4/24 via 66.77.88.99 metric 2
```

 or for the default route 

```
ip route del default

ip route add default via 66.77.88.99 metric 2
```

You can add the metric specification to routes_eth0 and routes_ath0 in /etc/conf.d/net (provided you use a new enough baselayout and have modules_eth0=("iproute2") of course)

----------

## bunkacid

Thanks for the update on ifconfig being flawed.  Something was fishy.

I forgot to mention previously that currently my config files are setup for iproute2, and dhcp.  I was using ifconfig to show my struggle.

I use dhcp for both interfaces, which allows easy portability of my laptop between networks.

I'd rather not have to deal with specific routes, but rather the whole interface itself.  Sticking specific static routes in my configuration makes things more of a hassle.

Simplicity would be beautiful.  Why doesn't there seem to a way to change the metric of the whole interface and not just individual routes?

baselayout     1.11.8

iproute2          2.6.9.20040831

----------

## moocha

Weeeeellll...

 *man netdevice wrote:*   

> SIOCGIFMETRIC, SIOCSIFMETRIC
> 
> Get  or  set  the  metric of the device using ifr_metric.  This is currently not implemented; it sets ifr_metric to 0 if you attempt to read it and returns EOPNOTSUPP if you attempt to set  it.

 

 *net/core/dev.c wrote:*   

> 
> 
> ```
> /*
> 
> ...

 

Guess that says it all... It was probably a Debian patch.

Still, I'm very uncomfortable with the idea of the interface metric. The metric is conceptually associated with a specific route. "Default value" type metrics should be handled in userspace, not at kernel level...

----------

## bunkacid

Considering changing the metric of an interface is something that is possible on a Cisco, a Win32 box, and other linux distro's.  When I found the metric in the bash-completion in Gentoo, I figured it would have worked.  I suppose I'm just a bit of a control freak who got used to a useful feature.

But how else would you be able to roam from the wifi, to the wired lan, without downing an interface and or manualy updating the routes to higher metrics?

I guess more work is needed with the networking scripts to make them smarter.  I'm sure there's others who use their laptops in a similar fashion.

I've been digging around more in iproute2.

```
 #/etc/conf.d/net

routes_ath0=(

        "192.168.48.0/24 dev ath0 proto kernel scope link metric 2"

        "default dev ath0 metric 2 scope global"

)

routes_eth0=(

        "192.168.48.0/24 dev eth0 proto kernel scope link metric 1"

        "default dev eth0 metric 1 scope global"

)

```

This seems to set the metric for the device, but I don't like having the static local network route in there and it still doesn't fix the main issue.

 It's a shame, the routes_XXX can't delete/change routes only append them.  Now if I could just figure out how to include some more functionality, and some special variables, that tells the scripts to re-write the other routes just added by the dhcp clients.  Or have them set a default metric when they add the routes. 

Oi.  Headache.

----------

## moocha

 *bunkacid wrote:*   

> Oi.  Headache.

 

Heh  :Very Happy: 

Still you have a valid point there - me being a purist is all well but that tends not to help that much with practical issues... Maybe you could remember or figure out what Debian kernel that was? I could then try and take a peek around for the patch and try to integrate it into the gentoo-dev-sources kernel (assuming you're 2.6). Then we could submit it to Bugzilla and perhaps get it into the standard gentoo-dev-sources patchset.

----------

## Syntaxis

 *bunkacid wrote:*   

> Simplicity would be beautiful. Why doesn't there seem to a way to change the metric of the whole interface and not just individual routes?

 

Is Debian's ifmetric package not what you're looking for?

 *Quote:*   

> ifmetric is a Linux tool for setting the metrics of all IPv4 routes attached to a given network interface at once.

 

----------

## bunkacid

Hey moocha,

Thanks for the help.

The last Debian kernel I was using was their debian flavored 2.6.7 without any extra patches.

----------

## bunkacid

 *Quote:*   

> 
> 
> Is Debian's ifmetric package not what you're looking for?
> 
> ifmetric is a Linux tool for setting the metrics of all IPv4 routes attached to a given network interface at once.

 

Sounds like a neat tool, but the changes to the metric were made using just "ifconfig ath0 metric 2" in the local boot script while I was using Debian.

----------

