How to find ip address of Linux KVM guest virtual machine

How do I find out an IP address of Linux KVM guest from Linux host itself? I wanted to ssh into KVM guest VM. How can I find the IP address of a KVM Virtual Machine Guest on a CentOS Linux 7.x/8.x server?

There are various ways to get the IP address of KVM guest from the host. If you are using virbr0 (default bridge) use the virsh command. It is also possible to use the combination of arp command or check DHCP server log if you are using a dedicated DHCPD over a bridged network such as br0 that give access to physical LAN.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements KVM and Linux
Est. reading time 3 minutes

Steps to find the ip address of Linux KVM guest virtual machine

  1. Open the terminal app or login using ssh to host server
  2. Get the network list: virsh net-list
  3. Type the command: virsh net-dhcp-leases networkNameHere

Let us see steps in details.

Method 1 – Find the IP addresses of VMs in KVM with virsh

Type the following command to list network:
# virsh net-list
# virsh net-info default
# virsh net-dhcp-leases default

Here is another session for my centos-8-cloud VM:
$ virsh net-dhcp-leases default

 Expiry Time           MAC address         Protocol   IP address          Hostname         Client ID or DUID
 2020-08-23 18:53:39   52:54:00:33:0c:ee   ipv4   centos-8-cloud   01:52:54:00:33:0c:ee

You can type the ssh command to log in to OpenBSD VM named nixcraft-openbsd with IP address
$ ssh vivek@
For CentOS 8 vm:
$ ssh
$ ssh vivek@

Method 2 – Get the IP address of Linux KVM guest using domifaddr

Find network interfaces’ addresses for a running domain called freebsd11.1:
$ virsh list
$ virsh domifaddr freebsd11.1

Combine both virsh and bash shell while loop as follows:

virsh list --name | while read n 
  [[ ! -z $n ]] && virsh domifaddr $n

Method 3 – Use arp command to get a KVM guest’s IP address

Use the virsh command to find out the mac address of domain:
$ virsh list
$ virsh dumpxml VM_NAME | grep "mac address" | awk -F\' '{ print $2}'
$ arp -an | grep 52:54:00:ce:8a:c4

In short use any one of the following virsh command to get the ip address

$ virsh list
$ virsh domifaddr rhel7

Say hello to Libvirt NSS module

When it comes to managing guests and executing commands inside them, logging into guest operating system and doing the job is convenient. Users are used to ssh in this case. Ideally,
ssh user@ip-Address-Here
But depending on virtual network configuration it might not be always possible. For instance, when using libvirt NATed network it’s dnsmasq (spawned by libvirt) who assigns IP addresses to domains. But by default, the dnsmasq process is then not consulted when it comes to host name translation. Users work around this problem by configuring their libvirt network to assign static IP addresses and maintaining /etc/hosts file in sync. But this puts needless burden onto users. This is where NSS module comes. Install it using the yum command/dnf command/apt command/apt-get command:
$ sudo yum install libvirt-nss ## RHEL/CentOS/Fedora ##
$ sudo apt install libnss-libvirt ## Debian/Ubuntu ##

Make sure /etc/nsswitch.conf updated as follows. Verify it using the grep command:
$ grep -w 'hosts:' /etc/nsswitch.conf

files libvirt libvirt_guest dns mymachines

Now list vm and try to use the ping command or ssh command to resolve those VMs via ibvirt NSS module:
$ virsh list
$ ping vm-name-here
$ ssh user@vm-name-here

Finding the IP address of a KVM Virtual Machine/Guest using CLI

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • JUAN ENCISO CONDENA Sep 28, 2020 @ 15:18

    Great post. Very simple and didactic. Thanks for share your tips

  • James K T Mar 3, 2021 @ 21:39

    Was thinking about how to find the IP address of a KVM virtual machine on my CentOS 8 server. This page was very useful. Now writing script to do some automation.

    • Maggie Jordan Apr 8, 2021 @ 3:40

      Same but I am currently working on Debian 10.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum