宿主机如何获取kvm虚拟机的ip地址

参考 https://stackoverflow.com/questions/13552881/can-i-determine-the-current-ip-from-a-known-mac-address # Can I determine the current IP from a known MAC Address?

  • 最佳实践,通过nmap扫描来更新 arp 缓存表,然后 通过命令:arm -n 来获取mac地址和ip的映射关系
I don't think there is a single command to do this. One hack would be to do a ping scan or a broadcast ping on the subnet and then query the arp table for the IP address of the MAC address. Obviously not an ideal solution. Example:

nmap -sP 192.168.1.0/24 >/dev/null && arp -an | grep  | awk '{print $2}' | sed 's/[()]//g'

Here nmap will do a ping scan and populate your arp cache. Once the scan is done, the arp command can be used to print the arp table and then you pull out the IP address with grep/awk. You could try replacing nmap with a broadcast ping, but that probably isn't as reliable.

你可能感兴趣的:(tcp/ip,数据库,网络协议)