如何通过URL删除ip路由?

Fel*_*lix 1 linux networking iproute

运行(可能已损坏)openvpn 脚本后,我有一个 IP 路由表,其中一个条目是 URL:

# netstat -r                                        
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         10.0.0.1        0.0.0.0         UG        0 0          0 wlp58s0
10.0.0.0        0.0.0.0         255.255.255.0   U         0 0          0 wlp58s0
google.com      10.0.0.1        255.255.255.255 UGH       0 0          0 wlp58s0
Run Code Online (Sandbox Code Playgroud)

如何删除最后一行?常规方式抛出错误:

# ip route del google.com
Error: any valid prefix is expected rather than "google.com".
Run Code Online (Sandbox Code Playgroud)

如果这很重要,我在 gentoo linux 上。

roa*_*ima 5

该条目google.com不是 URL;它是一个域名,也可能是一个主机名。(不过,它可能是 URL 的一部分。)

如果您使用,netstat -rn您将在第一列中获得 IP 地址而不是名称。从那里您可以删除路由 - 再次参考其网络和子网寻址。

netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         server.roaima   0.0.0.0         UG        0 0          0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
google.com      0.0.0.0         255.255.255.255 UH        0 0          0 eth1

netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.2.2     0.0.0.0         UG        0 0          0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
216.58.198.174  0.0.0.0         255.255.255.255 UH        0 0          0 eth1

route delete -host 216.58.198.174
Run Code Online (Sandbox Code Playgroud)

您也可以使用较新的ip route,它仅列出带有 IP 地址的路由。使用ip route del删除不需要的条目。