Find KVM VM’s IP from Host

Create following function in your .bash_profile

FIND_VMIP() {
  VM=$1
  IP=$(arp -e | grep $(sudo virsh domiflist ${VM} |grep vnet| awk '{print $5}') | awk '{print $1}')
  echo "VM ${VM} has IP ${IP}"
}

Create an alias

alias vmip=FIND_VMIP

Reload .bash_profile

source ~/.bash_profile

Now run command vmip to find ip.

Example:

$ sudo vmip myvm
VM myvm has IP 192.168.122.178

 Share!