什么是 ip 路由度量,如何更改它?

什么是 ip 路由度量,如何更改它?

当我跑步时ip route,我看到

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

所有这些都有其metric设置100。这是在哪里记录的,以及ip(notifconfigroute)用于仅更改指标的现代语法是什么?我没有看到metric记录在man ip route

答案1

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 路由状态路由首选项。度量值越低,路由的优先级越高。


虽然语法需要大量重复,但您可以ip像这样更改它们

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

就我而言,我使用了这个,

sudo ip route replace default via 10.2.64.1 dev ens4 metric 90

现在我的ip route节目,

$ 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

相关内容