How to find the IP address of Linux guests

There’s a lot of examples in the internet showing how you can obtain the IP address of a libvirt guest virtual machine. Most of the examples show how to do that when the network is using NAT forwarding (aka “Virtual Networks”).

However, how to do that if your setup is using Bridged Networking and your guests receive an IP address from an external DHCP server?

One idea is to install the read the DHCP leases file straight from the guest FS. You can do that by using the libguestfs-tools to cat the file within the image. For RHEL 6 (and CentOS 6 and similar distributions) the process is similar to this:

For RHEL 7 (as well as CentOS 7 and similar) the process is slightly different due to the way NetworkManager stores the leases file:

In this Gist there’s a modified script I used to update the IP address of all guests in one shot.

Published by

Otavio Piske

Just another nerd

Leave a Reply

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