2015-04-22 39 views
0

我想将wwan0接口的DNS /网关获取到变量中。有没有其他的方式(更强大)比存储在选项卡中的路由命令的结果和通过使用此ID获取值?解析路由获取网关/ DNS

[email protected] :~# route 
Kernel IP routing table 
Destination  Gateway   Genmask   Flags Metric Ref Use Iface 
default   176.28.206.105 0.0.0.0   UG 0  0  0 eth0 
176.24.196.164 *    255.255.255.224 U  0  0  0 wwan0 
176.26.210.210 176.28.211.211 255.255.255.255 UGH 0  0  0 eth0 
176.28.4.4  *    255.255.0.0  U  0  0  0 eth0 
172.24.201.100 *    255.255.255.255 UH 0  0  0 eth0 

回答

0

我不太清楚,你的意思是“检索DNS /网关”。但是,如果你的意图得到的route输出为wwan0接口的前两列,那么这可能是有用的:

dest=$(route | awk '{if($8=="wwan0") print $1}') 
gw=$(route | awk '{if($8=="wwan0") print $2}') 
echo "data for wwan0: $dest/$gw" 

打印

data for wwan0: 176.24.196.164/* 
在你的路由表的情况下