How could i set the metric for a dhcp device?


i have two devices in my computer eth1 and eth2.
each device gets the ip address via dhcp.

each device set the route to their network at startup.
but i wanna eth2 to have a higher route metric.
something like “metric 4”

Could i set the metric number in a file like ifcfg-eth2 or ifroute-eth2 ?

I didn’t found something.


I didn’t get an answer how to configure it the right way.
But if someone hase the same problem here is my not so good, but working workaround:

i get the programm “ifmetric” from:

ifmetric 0.3

And now i just start this command after if-route-up :

ifmetric dsl0 30

if someone has a better idea please let me know.

cu all

Are you trying to use the Microsoft base metric option?

While you can synthesize such an option under ISC DHCPD (or are you using Microsoft DHCPD?), the author of ifmetric says that Linux DHCP clients don’t pay attention to this option.

What you might be able to do is modify the standard dhclient script /sbin/dhclient-script to extract the metric option from the lease and then call ifmetric with that number. You’ll need some shell scripting skills.

if it is a dhcp connection and not a static or a pppd/pppoe connection. then you could use this line in the /etc/sysconfig/ifcfg-* file.


or in my case i want my cable modem be the prio one so i used:

DHCPCDARGS=’–metric -10’


the problem is, that dsl0 is not using dhcpcd to get the ip address. it must be some routine in the pppoe protocol. or am i wrong here?

maybe i can use “/etc/ppp/ip-up.d” to set the metric? Did these scripts always run on a reconnect of a dsl connection?
(cinternet -i dsl0 --stop && cinternet -i dsl0 --start)

There is a scheme where you can create your own script hooks when interfaces come up or go down. If you look at /etc/sysconfig/network/if-up.d, you will see some scripts that are actually symlinks to …/scripts/something. Scripts in this if-up.d directory get called when an interface comes up. The script can look at the interface name, passed as an argument, and decide whether to do anything. Similarly for if-down.d.