这是用户在 2024-11-27 16:20 为 https://bbs.archlinux.org/viewtopic.php?id=221046 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

You are not logged in.
您尚未登录。

#1 2016-12-24 08:11:34

h.safe H.SAFE 安全
Member 成员
Registered: 2016-08-01 注册日期:2016 年 8 月 1 日
Posts: 31 帖子: 31

[Resolved]How to change the default route metric
[已解决]如何更改默认路由指标

Hi, 你好

I am running into a problem and would like to know a quick fix to that. Currently ip route default GW has got the values:
我遇到了一个问题,想知道一个快速的解决方案。目前 ip route default GW 的值为:

default via 192.168.10.1 dev eth0 proto static metric 100
默认通过 192.168.10.1 Dog eth0 Proto 静态公制 100

default via 192.168.42.129 dev usb0 proto static metric 101
默认通过 192.168.42.129 Dog USB0 Proto 静态公制 101

I would like to change the metric value of the usb0 interface temporarily lower than the eth0 to be chosen for the outgoing traffic. How can I achieve this?
我想将 usb0 接口的度量值暂时更改为低于 eth0 的指标值,以便为传出流量选择。我该如何实现这一点?

Thanks 谢谢

Last edited by h.safe (2016-12-27 11:59:48)
最后由 h.safe 编辑 (2016-12-27 11:59:48)


Why did Bodhidharma come from the west?
为什么达摩来自西方?

Offline 离线

#2 2016-12-24 08:30:09

Into the Pit
Member 成员
Registered: 2010-09-04 注册日期: 2010-09-04
Posts: 37 帖子: 37

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

could be easily done with the
可以使用

ip route

command. see man ip-route for more info.
命令。有关详细信息,请参阅 man ip-route。

Offline 离线

#3 2016-12-24 09:21:14

h.safe H.SAFE 安全
Member 成员
Registered: 2016-08-01 注册日期:2016 年 8 月 1 日
Posts: 31 帖子: 31

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

I couldn't and I appreciate you to share that "easily" one line code here ...
我不能,我很感激你在这里分享那个 “轻松 ”的一行代码......


Why did Bodhidharma come from the west?
为什么达摩来自西方?

Offline 离线

#4 2016-12-24 13:11:04

seth 赛斯
Member 成员
Registered: 2012-09-03 注册日期: 2012-09-03
Posts: 58,786 帖子: 58,786

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

How long did you try? Try again, maybe invoke google.
你试了多长时间?再试一次,也许调用 google。

The solution is absolutely straightforward and posting it *will* be embarrassing.
解决方案绝对简单明了,发布它*会*令人尴尬。

Offline 离线

#5 2016-12-26 05:49:19

h.safe H.SAFE 安全
Member 成员
Registered: 2016-08-01 注册日期:2016 年 8 月 1 日
Posts: 31 帖子: 31

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

Embarrassing is the hollow reply posts that gets people nowhere but a count up for you...try google and immediately will get to know it is not at all a simple straight forward solution to it in Linux boxes and particularly when multiple default routes are in question...
令人尴尬的是那些空洞的回复帖子,它让人们无处可去,只能为你数一数......尝试 Google,很快就会知道在 Linux 机器中根本不是一个简单的直接解决方案,尤其是当存在多个默认路由时......


Why did Bodhidharma come from the west?
为什么达摩来自西方?

Offline 离线

#6 2016-12-26 08:40:56

seth 赛斯
Member 成员
Registered: 2012-09-03 注册日期: 2012-09-03
Posts: 58,786 帖子: 58,786

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

ip route del default via 192.168.42.129 dev usb0 proto static metric 101
ip route add default via 192.168.42.129 dev usb0 proto static metric 99

Do yourself a favor and use a smartphone instead.
帮自己一个忙,改用智能手机。

Offline 离线

#7 2016-12-26 10:25:55

brebs 布雷布斯
Member 成员
Registered: 2007-04-03 注册日期: 2007-04-03
Posts: 3,742 帖子: 3,742

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

There doesn't seem to be a one-liner to change an existing metric, strangely.
奇怪的是,似乎没有一行话来改变现有的指标。

In general, I would prefer adding the new route entry *first*, to prevent a short time period where there might be no route (not applicable to this particular example, I know).
一般来说,我更愿意 *首先* 添加新的路由条目,以防止短时间内可能没有路由(我知道,不适用于这个特定示例)。

Offline 离线

#8 2016-12-26 12:33:06

seth 赛斯
Member 成员
Registered: 2012-09-03 注册日期: 2012-09-03
Posts: 58,786 帖子: 58,786

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

The one-liner would be "ip route change ..." but it fails on many realtek chips, unfortunately.
单行代码是 “ip route change ...”但不幸的是,它在许多 Realtek 芯片上都失败了。

You can reverse the calls (add first, then del) - should bear no harm either.
你可以撤销调用(先添加,再 del)——也应该不会有什么坏处。

Offline 离线

#9 2016-12-26 12:49:25

ayekat 阿耶卡特
Member 成员
Registered: 2011-01-17 注册日期: 2011-01-17
Posts: 1,611 帖子: 1,611

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

seth wrote: seth 写道:

The one-liner would be "ip route change ..." but it fails on many realtek chips, unfortunately.
单行代码是 “ip route change ...”但不幸的是,它在许多 Realtek 芯片上都失败了。

It fails on Intel chips, too. But anyway, why would setting network route metrics be dependent on hardware? Doesn't routing happen in the kernel anyway?
它在 Intel 芯片上也失败了。但无论如何,为什么设置网络路由指标取决于硬件呢?无论如何,内核中不进行路由吗?


pkgshackscfgblag
PKGs黑客cfgblag

Offline 离线

#10 2016-12-26 13:11:53

seth 赛斯
Member 成员
Registered: 2012-09-03 注册日期: 2012-09-03
Posts: 58,786 帖子: 58,786

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

I've never digged into it but it looks like some ioctl fails due to some blocked(?) rtnetlink socket. I've frankly no idea which causes this, the actual kernel module or its state *might* be relevant.
我从未深入研究过它,但看起来一些 ioctl 由于某些阻塞(?) rtnetlink 套接字而失败。坦率地说,我不知道是什么导致了这种情况,实际的内核模块或其状态*可能*是相关的。

I recall it to have worked on an intel chip, but this might be just coincidental -  I just checked and fails on a broadcom chip as well. It's probably not HW related at all then.
我记得它在 intel 芯片上工作过,但这可能只是巧合 - 我刚刚在 broadcom 芯片上检查了一下,也失败了。那可能根本不与 HW 相关。

Software or general kernel bug then.
然后是软件或一般内核错误。

Offline 离线

#11 2016-12-26 13:27:34

brebs 布雷布斯
Member 成员
Registered: 2007-04-03 注册日期: 2007-04-03
Posts: 3,742 帖子: 3,742

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

seth wrote: seth 写道:

The one-liner would be "ip route change ..." but it fails on many realtek chips, unfortunately.
单行代码是 “ip route change ...”但不幸的是,它在许多 Realtek 芯片上都失败了。

Let's see an actual command that should *work*, from you, rather than insults.
让我们看看一个实际的命令,它应该 *有效*,来自你,而不是侮辱。

AFAICT, it is not possible to *change* an existing metric, using the "ip" command - which I reckon is a bug with the "ip" command sad
AFAICT,无法使用“ip”命令*更改*现有指标 - 我认为这是“ip”命令 sad 的一个错误

Offline 离线

#12 2016-12-26 13:50:15

seth 赛斯
Member 成员
Registered: 2012-09-03 注册日期: 2012-09-03
Posts: 58,786 帖子: 58,786

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

I've never promised a one-liner, neither did "Into the Pit", that's h.safe's claim.
我从来没有承诺过单行话,“Into the Pit”也没有,这是 h.safe 的说法。

And add/remove *does* change this, is straight forward and *very* simple to figure?
添加/删除 * 是否* 会改变这一点,是直接且 * 非常 * 容易理解的吗?

You could even shadow ip route change with an alias that does so, so don't jump around on insinuated promises and call me insulting - I said this is trivially easy to figure and it *is* on the first google result and requires nothing but copy + paste magic. The OP didn't ask "why does ip change not work" (for he could have then googled the error and found "use add/del" on the first google result *again*
你甚至可以用这样做的别名来影子 ip 路由更改,所以不要跳来跳去暗示的承诺并称我为侮辱 - 我说这很容易理解,它*在*第一个 google 结果中,只需要复制 + 粘贴魔法。OP 没有问“为什么 ip 更改不起作用”(因为他本可以在谷歌上搜索错误并在第一个 google 结果*再次*上找到 “use add/del”

And what and do you believe would happen to your  routing table when "change" did work? Either you got two routes (add/del) briefely none (del/add) or an atomic action (ie a grand kernel lock).
您认为当 “change” 确实有效时,您的路由表会发生什么情况?要么你有两条路由 (add/del),要么没有 (del/add),要么有一个原子操作(即大内核锁)。

Offline 离线

#13 2016-12-26 15:36:00

ewaller
Administrator 管理员
From: Pasadena, CA 来自: 加利福尼亚州帕萨迪纳
Registered: 2009-07-13 注册日期:2009 年 7 月 13 日
Posts: 20,209 帖子: 20,209

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

h.safe wrote: h.safe 说:

Embarrassing is the hollow reply posts that gets people nowhere but a count up for you...try google and immediately will get to know it is not at all a simple straight forward solution to it in Linux boxes and particularly when multiple default routes are in question...
令人尴尬的是那些空洞的回复帖子,它让人们无处可去,只能为你数一数......尝试 Google,很快就会知道在 Linux 机器中根本不是一个简单的直接解决方案,尤其是当存在多个默认路由时......

https://wiki.archlinux.org/index.php/Co … ther_users
https://wiki.archlinux.org/index.php/Co ...ther_users

https://wiki.archlinux.org/index.php/Co … _not_flame
https://wiki.archlinux.org/index.php/Co ... _not_flame

Note, this is not based solely on my opinion.
请注意,这不仅仅是基于我的观点。


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
如果它与自然法则相一致,那么没有什么是美妙得令人难以置信的 -- 迈克尔·法拉第(Michael Faraday

Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
有时是那些没有人能想象到任何事情的人,他们做了没有人能想象的事情。-- 艾伦·图灵

---
How to Ask Questions the Smart Way
如何以聪明的方式提问

Offline 离线

#14 2016-12-27 11:53:51

h.safe H.SAFE 安全
Member 成员
Registered: 2016-08-01 注册日期:2016 年 8 月 1 日
Posts: 31 帖子: 31

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

Hello all, 大家好,
Thanks everyone on this, 谢谢大家,
a reminder of the forum name :Newbie Corner...
提醒论坛名称 :Newbie Corner...


Why did Bodhidharma come from the west?
为什么达摩来自西方?

Offline 离线

#15 2016-12-27 13:53:22

seth 赛斯
Member 成员
Registered: 2012-09-03 注册日期: 2012-09-03
Posts: 58,786 帖子: 58,786

Re: [Resolved]How to change the default route metric
回复:[已解决]如何更改默认路由指标

Yes, and not "customer service".
是的,不是 “Customer service”。

The problem is not the newbieness, the problem is that you asked, got a good hint where to look, NOT EVEN ONE HOUR later said "i can't, please tell me the exact line" and when being suggested that you should at least *try* for yourself first, because the answer really is so trivial, expressed to be offended to be asked to try google.
问题不在于新手,问题在于你问了,得到了一个很好的提示去哪里看,甚至不到一个小时后就说“我不能,请告诉我确切的台词”,当被建议你至少应该先自己*尝试*时,因为答案真的太微不足道了,表示被要求尝试谷歌被冒犯了。

This is considered help vampirism and not how things work. You get assistance on learning or figuring things, but don't get your problems solve, because you're simply too lazy to figure yourself. And don't tell me that you got the hint, really tried, failed and asked back - within 50 minutes, while just googling for "ip route change metric" virtually spams the answers in your face.
这被认为是帮助吸血鬼,而不是事情的运作方式。你在学习或弄清楚事情方面得到帮助,但你的问题没有得到解决,因为你只是懒得自己弄清楚。不要告诉我你得到了提示,真的尝试过,失败了,然后又问了 - 在 50 分钟内,而只是在谷歌上搜索“ip route change metric”几乎是当着你的面回答的垃圾邮件。

Had you returned with "tried ip route change but it always says error"  or "i don't understand what the NODE_SPEC in the manpage means", this discussion would have taken an entirely different route.
如果你返回“tried ip route change but it always says error”或“I don't understand what the the NODE_SPEC scripting in the manpage”,这个讨论会走完全不同的路线。

Offline 离线

Board footer

Save to Cacher 保存到缓存
Save to Cacher 保存到缓存