Quantcast
Channel: Earl C. Ruby III – Earl C. Ruby III
Viewing all articles
Browse latest Browse all 61

How to get the IP address of a KVM/virsh VM

$
0
0

Since virsh domifaddr doesn’t work to get the IP addresses of VMs on a bridged network, I wrote a get-vm-ip script (which you can download from Github) which uses this to get the IP of a running VM:

HOSTNAME=[your vm name]
MAC=$(virsh domiflist $HOSTNAME | awk '{ print $5 }' | tail -2 | head -1)
arp -a | grep $MAC | awk '{ print $2 }' | sed 's/[()]//g'

The virsh command gets the MAC address, the last line finds the IP address using arp.

Hope you find this useful.


Viewing all articles
Browse latest Browse all 61

Trending Articles