【问题标题】:How to get the gateway MAC address in Unix-like systems [closed]如何在类 Unix 系统中获取网关 MAC 地址 [关闭]
【发布时间】:2014-05-28 21:02:23
【问题描述】:

我已连接到 IP 地址类似于 192.168.xxx.xxx 的专用网络。我知道默认网关的 IP 地址,但如何获取网关 MAC 地址?我正在研究 iMac 和 Linux 机器。有什么 Unix 命令可以做到吗?

【问题讨论】:

标签: linux macos unix ubuntu networking


【解决方案1】:

这会给你所有的清单:

netstat -rn 

或者这个获取默认网关:

netstat -rn | grep 'default'

你真正想要的:

netstat -rn | grep 'default' | awk '{print $2}'

【讨论】:

  • 在 Centos 7 中,输出不包括 MAC 地址。
【解决方案2】:

这里是arping 的命令行示例,假设您的网关的 IP 地址是 192.168.1.1 并且您已通过 eth0 进行连接:

arping -f -I eth0  192.168.1.1
ARPING 192.168.1.1 from 192.168.1.24 eth0
Unicast reply from 192.168.1.1 [ab:cd:ef:01:02:03]  1.030ms
Sent 1 probes (1 broadcast(s))
Received 1 response(s)

所以在这种情况下网关的 MAC 地址是ab:cd:ef:01:02:03

【讨论】:

  • 我使用了这个解决方案而不是 netstat 因为 netstat -rn 在 Centos 7 中不包含 MAC 地址。
猜你喜欢
  • 1970-01-01
  • 2013-09-18
  • 1970-01-01
  • 2012-11-18
  • 1970-01-01
  • 2022-10-14
  • 1970-01-01
  • 2011-09-29
  • 1970-01-01
相关资源
最近更新 更多