Linux ip route del 不删除整个表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19663727/
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-07 01:13:04  来源:igfitidea点击:

ip route del does not delete entire table

linuxrouting

提问by Vincent Ketelaars

I have recently started using ip routecommands for advanced routing stuff. Now I have come across something rather puzzling to me. A default route added to a table will be easily deleted whereas another route remains.

我最近开始使用ip route高级路由命令。现在我遇到了一些令我感到困惑的事情。添加到表中的默认路由将被轻松删除,而另一条路由则保留。

I add these two rules:

我添加了这两个规则:

ip route add dev wlan0 default via 192.168.0.1 table 21
ip route add dev wlan0 192.168.0.0/24 table 21

Now if I do:

现在,如果我这样做:

ip route show table 21

I see both of these rules present.

我看到这两条规则都存在。

default via 192.168.0.1 dev wlan0 
192.168.0.0/24 dev wlan0  scope link  

If I then try to delete table 21, and show it again:

如果我然后尝试删除表 21,并再次显示它:

ip route del table 21
ip route show table 21

There is still that rule remaining.

该规则仍然存在。

192.168.0.0/24 dev wlan0  scope link

Can anyone explain this? The man page says that del is designed to delete a ROUTE, which also includes tables.

谁能解释一下?手册页说 del 旨在删除 ROUTE,其中还包括表。

采纳答案by nic

As @user3291010 has already pointed out, to delete a full table, use the following command:

正如@user3291010 已经指出的那样,要删除一个完整的表,请使用以下命令:

This command deletes table 21:

此命令删除表 21:

ip route flush table 21

The command you tried is used to remove specific rules from a table. It wants a prefix to match on. When you didn't supply the prefix, it just deleted the first entry, which happened to be the default route.

您尝试的命令用于从表中删除特定规则。它需要一个前缀来匹配。当您没有提供前缀时,它只是删除了第一个条目,这恰好是默认路由。

To remove the second entry, and only the second entry, you could run this command:

要删除第二个条目,并且仅删除第二个条目,您可以运行以下命令:

ip route delete table 21 192.168.0.0/24

As far as I know, there is no way to delete all entries using the deletecommand.

据我所知,无法使用该delete命令删除所有条目。

回答by ancientt

Maybe try:

也许尝试:

ip route flush table 21