Azimout's Linux weblog

libvirt domain ip address

leave a comment »

If you are using virsh / qemu / libvirt / kvm for your virtual machines and you type “virsh help” in a terminal, you’ll get more than 200 possible commands that you can use to manipulate your host, domains, etc.

However, I couldn’t for the life of me find a command that will give you a VM’s IP address. Apparently other people have the same problem, cause you can find several scripts out there that try to provide this functionality. The simplest way I have found is to obtain the MAC address with “virsh domiflist <domain>”, and then grep your syslog for that MAC address: you’ll get a bunch of dnsmasq-dhcp log lines matching IP to MAC.

The reason I wanted to find the VM’s IP address was in order to ssh into it. So far I had worked around that by giving it a static IP address (in the 192.168.122.x range, of course) and adding a record to my host’s /etc/hosts file. Instead, today I discovered that if you know the hostname you gave your VM (might be different from the domain name), your host will know it as <vm’s hostname>.local!!!


Written by azimout

01/03/2013 at 22:52

Posted in Tricks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: