Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a small fleet of KVM/libvirt hosts with a few hundred virtual machines on it, managed by a group of sysadmins in disparate locations. I've run into a problem where I am connected to a virtual machine by SSH, but I can't figure out the name of the bare metal host which owns it. Does anyone know a way to find the name of the bare metal host from inside a virtual machine?

If this isn't something KVM does out of the box, are there any examples of configurations we could apply on all our hypervisors to expose this information?

We do use inventory management software to keep track of our virtual machines & their bare metal hosts - however it has bugs, and from time to time we lose track of what host owns a virtual machine. I'll fix this problem - but the concept of finding a KVM host from inside a VM would be useful regardless.

I know this goes against many security principles employed in shared environments where each virtual machine is a product sold to a different customer - but in our environment where we own the hosts, the security is not an issue.

share|improve this question
This guy says its not possible, but I am still looking around... – i.h4d35 Jun 21 '13 at 6:22

I'm pretty damn sure this isn't possible, for security reasons.. Not to do what you want to directly, by querying the guest.

However, you could install a scriptable agent on the host, then use something like virsh list to dump a list of VM names, and have a policy (actually a meatspace policy, not a technical one) to ensure that the hostname of the guest exactly matches the VM name.

OR.. Do the same as above, except use something like virsh to dump the VM name, and the IP address of the guest, then recursively work your way through the list, sshing into them in order, running some kind of data collection script, and shoving it into your inventory.

That way, you know the host it was run on (because you ran virsh from it and got a list), and you know what's running there.

Doesn't have to be virsh, you can do most/all of this with libvirtd directly, or the Python bindings thereof.

share|improve this answer

Not possible without working around the issue, basically some sort of agent in the VM that would keep the host data in it. If those guests migrate, then it's got to be updated via network somehow.

If you use a KVM management system (with hundreds of VMs, you definitely should) like oVirt, you can see on which host a VM runs in the admin control panel

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.