Linux 设置网络接口指标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10592612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:19:24  来源:igfitidea点击:

Set Network Interface Metric

linuxnetworkingarchlinux

提问by Thomas Hunter II

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.

我正在寻找执行此操作的命令行方法。我目前正在使用 Arch Linux,但最好使用与发行版无关的方法。

Here is my failed attempt:

这是我失败的尝试:

$ sudo ifconfig wlan0 metric 1
SIOCSIFMETRIC: Operation not supported

回答by AlexT

As stated in man ifconfig, metric is not a supported option for the ifconfigcommand on Linux systems, because when the ifconfigcommand is processed it doesn't create a routing table entry.

正如man ifconfig 中所述,Linux 系统上的ifconfig命令不支持 metric 选项,因为在处理ifconfig命令时,它不会创建路由表条目。

   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 routecommand, to add the route with the desired metric and delete the old entry. For example:

要回答您的问题,您必须使用route命令,添加具有所需指标的路由并删除旧条目。例如:

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