Centos:取得本機的MAC位址

Centos:取得本機的MAC位址

我有一個包含很多機器的本地網路。我需要從 CentOS 伺服器取得特定 IP 的 MAC 位址(並且需要針對數百個 IP 自動執行此操作)。

我已經嘗試過 ping + arp -a,但它似乎沒有跟踪這個 IP。

ping -c 3 10.101.2.11
PING 10.101.2.11 (10.101.2.11) 56(84) bytes of data.
64 bytes from 10.101.2.11: icmp_seq=1 ttl=63 time=0.531 ms
64 bytes from 10.101.2.11: icmp_seq=2 ttl=63 time=0.564 ms
64 bytes from 10.101.2.11: icmp_seq=3 ttl=63 time=0.576 ms

--- 10.101.2.11 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.531/0.557/0.576/0.019 ms

$ arp -a
? (10.1.0.101) at xx:xx:xx:xx:xx:xx [ether] on eth0
? (10.1.0.11) at xx:xx:xx:xx:xx:xx [ether] on eth0
gateway (10.1.0.1) at xx:xx:xx:xx:xx:xx [ether] on eth0
? (10.1.0.102) at xx:xx:xx:xx:xx:xx [ether] on eth0


在其他作業系統上arp-scan可能是取得裝置 MAC 的解決方案,但在 CentOS 上輸出很簡單:

$: arp-scan 10.101.2.11
Interface: eth0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.9.2 with 1 hosts (http://www.nta-monitor.com/tools-resources/security-tools/arp-scan/)
4 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.9.2: 1 hosts scanned in 1.815 seconds (0.55 hosts/sec). 0 responded

答案1

我在你的 arp -a 指令輸出中看到顯示 10.1.0 位址,而你的 ping 有 10.101.2,它們位於不同的網路上。 arp 將用於您所在的本地網路。

現在 ip neigh 是新的 arp -a 並且具有相同的行為。您必須進入該子網路才能查看這些電腦的 MAC 和子網路資訊。

你能透過 ssh 進入嗎?如果是這樣,如果您在那台機器上有憑證,您可以發送遠端命令並從那裡獲取 arp。

ssh [email protected] `ip neigh` 

我沒有使用過 arp-scan,但是透過查看文檔,它指出掃描本地網路。您嘗試連接 Mac 的電腦似乎位於另一個子網路中。

答案2

您的目標似乎生活在不同的網路上。您被告知 10.1.0.1 是網關,因為它沒有給出目標(IP 10.101.xx)的 MAC 位址,它們可能位於不同的網路上。位址從 10.1.0.1 到 10.101.0.0 意味著網路上有大約 60 萬台機器......

了解網路設定是什麼(網路遮罩、路由器…)。

相關內容