Linux: Get IP Address Of VM From KVM Host

This post will guide you how to find the IP address of VMs in KVM host in Linux system. How do I get a Virtual Machine’s IP address in KVM with virsh tool. How to find the ip address of KVM guest from the KVM host.

What is Virsh?


The virsh program is the main interface for managing virsh guest domains. The program can be used to create, pause, and shutdown domains. It can also be used to list current domains. Libvirt is a C toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes). It is free software available under the GNU Lesser General Public License. Virtualization of the Linux Operating System means the ability to run multiple instances of Operating Systems concurrently on a single hardware system where the basic resources are driven by a Linux instance. The library aims at providing a long term stable C API. It currently supports Xen, QEMU, KVM, LXC, OpenVZ, VirtualBox and VMware ESX.

Get IP Address Of VM From KVM Host


You can use the virsh tool to get the ip address of a virtual machine in kvm host. Assuming that you have a kvm guest named kvm1, and you want to get the ip address of this kvm guest. just type the following command:

#virsh domifaddr kvm1

outputs:

#virsh domifaddr kvm1 
Name MAC address Protocol Address
-------------------------------------------------------------------------------
 vnet0 52:54:10:f5:6d:d3 ipv4 192.168.122.8/24

You can also use the arp command in combination with virsh command to get the ip address of a given kvm vm.

Type the following command:

#vish dumpxml kvm1 | grep "mac address" | awk -F\' '{ print $2}'
# arp -an | grep 52:54:10:f5:6d:d3

List All KVM Guests with Virsh


you can use the virsh command to list all kvm guest in your current KVM host, just type the following command:

# virsh list --all

Outputs:

root@ca-ostest457 ~ # virsh list --all
Id Name State
----------------------------------------------------
7 kvm_1 running
8 kvm_2 running
9 kvm_3 running
11 centos7_qq running
- centos6_x86_64_kvm_1 shut off
- centos7_kvm_GUI shut off
- centos7_kvm_mini shut off

 

You might also like:

Sidebar



back to top