There are times when we start virtual machine and want to get ip address quickly without open any GUI or connecting virtual machines console. Here is the tip.
virsh domiflist Command
#!/bin/bash VMNAME=$1 for mac in `sudo virsh domiflist $VMNAME |grep -o -E "([0-9a-f]{2}:){5}([0-9a-f]{2})"` ; do arp -e | grep $mac | grep -o -P "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" ; done
The magic is that virtual machines interfaces are listed than mac address is grepped. After grepping mac address we are looking our ARP table to find corresponding ip address and put it to the screen. This script will list all interfaces of VM if it has more than one.
As we have provided as script we can use this script like below. We will name script as vm_ip and provide the virtual machine or VM name as parameter. VM name is ubu1 in this example.
$ ./vm_ip "ubu1"
1 thought on “How To Get Runnig VM Ip Address in Kvm/Libvirt”