对于bash集成,我需要从接口中检索默认网关。查找网关的接口
这里是命令路径的输出-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
我试图捕捉网关(PASSERELLE法文)为IFACE TUN0。
此正则表达式正在Rubular:
^[0\.]+\s+([\w\.]+)\s+.*UG.*tun0$
但这shell命令不起作用(无输出):
route -n |egrep -oh '^[0\.]+\s+([\w\.]+)\s+.*UG.*tun0$'
请告诉我为什么?
没有“接口的默认路由”这样的事情。默认路由是在内核路由表中的任何其他路由不能用于告知分组目的地时采用的路由。换句话说,对于所有接口,只能有一个[默认路由或网关](http://en.wikipedia.org/wiki/Default_gateway) – mvp