【问题标题】:Parse route to get gateway / DNS解析路由以获取网关/DNS
【发布时间】:2015-06-30 03:36:36
【问题描述】:

我想将 wwan0 接口的 DNS / 网关检索到一个变量中。除了将路由命令的结果存储在选项卡中并使用此 ID 获取值之外,还有其他方法(更强大)吗?

root@sn :~# 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

【问题讨论】:

    标签: linux bash shell dns routes


    【解决方案1】:

    我不太确定,您所说的“检索 DNS/网关”是什么意思。但是,如果您打算获取 wwan0 接口的 route 输出的前两列,那么这可能会有所帮助:

    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 / *
    

    以您的路由表为例。

    【讨论】:

      猜你喜欢
      • 2021-06-30
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      相关资源
      最近更新 更多