Can ssh into Ubuntu 20.04 virtual machine but domifaddr shows no IP

azaroseu asked:

I created an Ubuntu 20.04 virtual machine following this guide.
I am able to ssh into the virtual machine using the IP address I wrote in the network-config file, i.e., 192.168.122.101, however, when running virsh domifaddr <domain> and virsh net-dhcp-leases default, both show nothing, no IP address.

This only happens with Ubuntu 20.04 cloud images, with earlier Ubuntu versions and all CentOS cloud images I can see the assigned IP addresses using the above commands.

Any thoughts on this?

My answer:


You chose to reconfigure your new virtual machine with a manually configured IP address rather than to obtain it from DHCP, as is the default for cloud images. If you had left it configured to use DHCP, it would have just continued to work.

By default virsh domifaddr queries the DHCP server lease table to find the guest’s IP addresses. With manually configured addresses in the guest, there is nothing to find here, so it can show nothing.

You can instead ask it to query the guest using the QEMU guest agent. This agent should be installed and running by default on cloud images that target the KVM hypervisor, e.g. focal-server-cloudimg-amd64-disk-kvm.img.

For example:

virsh domifaddr guestname --source agent

This returns a view of the network configuration from inside the guest, which will differ from the outside view, e.g. the guest network interface names will be shown instead of the host virtual interface names.

Compare:

# virsh domifaddr example-staging 
 Name       MAC address          Protocol     Address
-------------------------------------------------------------------------------
 vnet1      52:54:00:6b:3b:e4    ipv4         192.168.122.248/24

with:

# virsh domifaddr example-staging --source agent
 Name       MAC address          Protocol     Address
-------------------------------------------------------------------------------
 lo         00:00:00:00:00:00    ipv4         127.0.0.1/8
 -          -                    ipv6         ::1/128
 enp1s0     52:54:00:6b:3b:e4    ipv4         192.168.122.248/24
 -          -                    ipv6         fe80::72aa:277e:2feb:5e60/64

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.