3

When I run ip route, I see

default via 172.16.42.1 dev ens5 proto dhcp src 172.16.42.248 metric 100 
default via 172.16.42.1 dev ens3 proto dhcp src 172.16.42.79 metric 100 
default via 10.2.64.1 dev ens4 proto dhcp src 10.2.69.64 metric 100

All of these have their metric set to 100. Where is this documented, and what is the modern syntax to ip (not ifconfig or route) is used to change just the metric? I don't see metric documented in man ip route

Evan Carroll
  • 28,578
  • 45
  • 164
  • 290

1 Answers1

3

From ip-route(8):

    metric NUMBER
    preference NUMBER
        the preference value of the route.  NUMBER is an
        arbitrary 32bit number, where routes with lower
        values are preferred.

Ip routes state routing preferences. The lower the metric, the higher the priority of the route.


While the syntax requires a lot of duplication, you change them with ip like this

sudo ip route replace default via {IP} dev {DEVICE} metric {METRIC}

In my case, I used this,

sudo ip route replace default via 10.2.64.1 dev ens4 metric 90

And, now my ip route shows,

$ ip route
15:12:26 default via 10.2.64.1 dev ens4 metric 90 
default via 172.16.42.1 dev ens5 proto dhcp src 172.16.42.248 metric 100 
default via 172.16.42.1 dev ens3 proto dhcp src 172.16.42.79 metric 100 
default via 10.2.64.1 dev ens4 proto dhcp src 10.2.69.64 metric 100 
10.2.64.0/19 dev ens4 proto kernel scope link src 10.2.69.64 
10.42.0.0/24 dev cni0 proto kernel scope link src 10.42.0.1 
169.254.169.254 via 172.16.42.2 dev ens5 proto dhcp src 172.16.42.248 metric 100 
169.254.169.254 via 172.16.42.2 dev ens3 proto dhcp src 172.16.42.79 metric 100 
169.254.169.254 via 10.2.64.11 dev ens4 proto dhcp src 10.2.69.64 metric 100 
172.16.42.0/24 dev ens5 proto kernel scope link src 172.16.42.248 
172.16.42.0/24 dev ens3 proto kernel scope link src 172.16.42.79

Jin
  • 3
  • 2
Evan Carroll
  • 28,578
  • 45
  • 164
  • 290