GNU/Linux 相当于 BSD 的“route get ...”是什么?

Mar*_*ase 19 linux ip route

BSDroute命令有一个功能,可以显示为给定主机选择的路由。例如:

/Users/mhaase $ route get google.com
   route to: iad23s07-in-f8.1e100.net
destination: iad23s07-in-f8.1e100.net
    gateway: 10.36.13.1
  interface: en0
      flags: <UP,GATEWAY,HOST,DONE,WASCLONED,IFSCOPE,IFREF>
 recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
       0         0         0         0         0         0      1500         0 
Run Code Online (Sandbox Code Playgroud)

如果我手动弄乱路由表以确保路由规则按预期工作,我偶尔会发现这很有用。

GNU 版本的 route 没有这个相同的“get”子命令。GNU/Linux 有什么等价物或替代品吗?

小智 26

ip route get 74.125.137.100
Run Code Online (Sandbox Code Playgroud)

但它不做主机名解析(我认为这是一件好事)。该命令通常可从 iproute 或 iproute2 包中获得。

  • @jordanm,更像是:`dig google.com +short | xargs -tn1 ip route get` (5认同)
  • `ip route get "$(dig google.com +short)"` 用于主机名解析。 (3认同)