【发布时间】:2013-09-28 16:44:27
【问题描述】:
对于 bash 集成,我需要从接口检索默认网关。
这是命令 route -n 的输出
Table de routage IP du noyau
Destination Passerelle Genmask Indic Metric Ref Use Iface
0.0.0.0 p.p.p.p 128.0.0.0 UG 0 0 0 tun0
0.0.0.0 x.x.x.x 0.0.0.0 UG 100 0 0 eth0
10.43.0.1 10.43.0.5 255.255.255.255 UGH 0 0 0 tun0
10.43.0.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
y.y.y.y x.x.x.x 255.255.255.255 UGH 0 0 0 eth0
x.x.x.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
128.0.0.0 10.43.0.5 128.0.0.0 UG 0 0 0 tun0
我尝试为 Iface tun0 捕获网关(法语中的 Passerelle)。
这个正则表达式正在使用 Rubular:
^[0\.]+\s+([\w\.]+)\s+.*UG.*tun0$
但是这个shell命令不起作用(没有输出):
route -n |egrep -oh '^[0\.]+\s+([\w\.]+)\s+.*UG.*tun0$'
请告诉我为什么?
【问题讨论】:
-
没有“接口的默认路由”之类的东西。默认路由是在内核路由表中的任何其他路由无法用于告知数据包目的地的情况下采用的路由。也就是说,所有接口只能有一个default route or gateway