2015-04-22 36 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/* 
在你的路由表的情況下