How to get the IP addresses of VMs in KVM with virsh

Posted on In QA

When we create VMs in KVM, we may don’t know the IP addresses because they are automatically assigned by DHCP. So we want to get them in VMM so that can login by SSH.

Do the commands as follows.

$ virsh domiflist hvm1
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet0      network    default    virtio      52:54:00:1c:36:cd
$ arp -e
Address                  HWtype  HWaddress           Flags Mask            Iface
10.80.1.17               ether   52:54:00:2b:08:c3   C                     br0
10.80.1.16               ether   52:54:00:78:02:89   C                     br0
10.80.1.18               ether   52:54:00:96:f6:59   C                     br0
kvm2                     ether   52:54:00:ec:31:68   C                     br0
kvm4                     ether   52:54:00:fd:4c:1e   C                     br0
kvm3                     ether   52:54:00:28:dd:2d   C                     br0
10.80.1.15               ether   52:54:00:f9:73:1e   C                     br0
kvm1                             (incomplete)                              br0
10.80.0.1                ether   00:50:56:b4:22:78   C                     br0
192.168.122.210          ether   52:54:00:1c:36:cd   C                     virbr0
10.80.0.11               ether   00:50:56:b4:22:7f   C                     br0

At last, you know the IP address of hvm1 is 192.168.122.210.

One comment

  1. Alternatively you can use the following sequence, which returns the IP addresses of all the VMs that are currently running:

    # Get the list of virtual networks

    virsh net-list

    # net-list returns the list of active networks. You’ll need to choose the one you want,
    # or just iterate through all of them with the next command:

    virsh net-dhcp-leases default

Leave a Reply

Your email address will not be published. Required fields are marked *