如何在Mac OSX中获取默认网关 [英] How to get default gateway in Mac OSX
问题描述
我需要在Mac机器上检索默认网关.我知道在Linux中,路由-n将给出输出,我可以从中轻松检索此信息.但是,这在Mac OSX(Snow Leopard)中不起作用.
I need to retrieve the default gateway on a Mac machine. I know that in Linux route -n will give an output from which I can easily retrieve this information. However this is not working in Mac OSX(Snow Leopard).
我也尝试过netstat -nr | grep 'default'
,但是我希望获得更干净的输出,例如Linux/Unix中route -n
产生的输出. netstat -nr
列出所有接口和它们的默认网关.
I also tried netstat -nr | grep 'default'
, but I was hoping for a cleaner output like that produced by route -n
in Linux/Unix. netstat -nr
lists all the interfaces and the default gateway for them.
任何向正确方向提出的建议或提示,将不胜感激.
Any kind of suggestion or a hint in the right direction will be appreciated.
推荐答案
您可以尝试:
route -n get default
它与GNU/Linux的route -n
(甚至是ip route show
)不同,但是对于检查默认路由信息很有用.
另外,您可以检查软件包将到达特定主机的路由.例如
It is not the same as GNU/Linux's route -n
(or even ip route show
) but is useful for checking the default route information.
Also, you can check the route that packages will take to a particular host. E.g.
route -n get www.yahoo.com
输出将类似于:
route to: 98.137.149.56
destination: default
mask: 128.0.0.0
gateway: 5.5.0.1
interface: tun0
flags: <UP,GATEWAY,DONE,STATIC,PRCLONING>
recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
0 0 0 0 0 0 1500 0
恕我直言netstat -nr
是您所需要的.甚至MacOSX的Network Utility应用程序(*)都使用netstat的输出来显示路由信息.
IMHO netstat -nr
is what you need. Even MacOSX's Network utility app(*) uses the output of netstat to show routing information.
我希望这会有所帮助:)
I hope this helps :)
(*)您可以使用open /Applications/Utilities/Network\ Utility.app
这篇关于如何在Mac OSX中获取默认网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!