<div dir="ltr">After installing and configuring the qemu-guest-agent in the guest - <a href="https://wiki.libvirt.org/page/Qemu_guest_agent">https://wiki.libvirt.org/page/Qemu_guest_agent</a><div> it should give you the IP with the domifaddr --source flag:</div><div><br></div><div># virsh domifaddr avocado-vt-vm1 --source agent<br></div><div> Name       MAC address          Protocol     Address<br>-------------------------------------------------------------------------------<br> lo         00:00:00:00:00:00    ipv4         <a href="http://127.0.0.1/8">127.0.0.1/8</a><br> -          -                    ipv6         ::1/128<br> enc1       52:54:00:22:36:1b    N/A          N/A</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 15, 2021 at 5:50 PM Charles Polisher <<a href="mailto:chas@chasmo.org">chas@chasmo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 9/9/21 11:11, Kaushal Shriyan wrote:<br>
<br>
> I have assigned static IP for all the below KVM Guest VM's. Is there a <br>
> way to find out the IP of the below VM's from virsh utility or any <br>
> other utility? virsh domifaddr testdobssbahrainms does not show the <br>
> static IP.<br>
><br>
> # virsh list --all<br>
>  Id   Name                      State<br>
> -----------------------------------------<br>
>  1    testdobssbahrainms         running<br>
<snip><br>
> # virt-install --version<br>
> 2.2.1<br>
> # cat /etc/redhat-release<br>
> CentOS Stream release 8<br>
><br>
> #virsh domifaddr testdobssbahrainms<br>
> #Name       MAC address          Protocol     Address<br>
> ------------------------------------------------------------------------------- <br>
><br>
><br>
Kaushal,<br>
<br>
Probably the following was gleaned from this very list,<br>
in the last year or so IIRC. Hope this works for you.<br>
As you can see below, the technique is to grep the MAC addresses<br>
from the domain definitions, e.g.:<br>
       # virsh dumpxml <domain> | grep 'mac address'<br>
       <mac address='52:54:00:30:fe:d8'/><br>
then grep the matching IP address from a listing of the<br>
hypervisor host's ARP table. e.g.:<br>
       # arp -an | fgrep '52:54:00:30:fe:d8'<br>
? (192.168.122.6) at 52:54:00:30:fe:d8 [ether] on virbr0<br>
    ^^^^^^^^^^^^^ here is the IP address.<br>
The script follows my sig.<br>
<br>
Best regards,<br>
-- <br>
Charles Polisher<br>
<br>
#!/usr/bin/perl -w<br>
<br>
# <br>
<a href="https://rwmj.wordpress.com/2010/10/26/tip-find-the-ip-address-of-a-virtual-machine/" rel="noreferrer" target="_blank">https://rwmj.wordpress.com/2010/10/26/tip-find-the-ip-address-of-a-virtual-machine/</a><br>
# Invocation: <a href="http://virt-addr.pl" rel="noreferrer" target="_blank">virt-addr.pl</a> <guestname><br>
<br>
use strict;<br>
use XML::XPath;<br>
use XML::XPath::XMLParser;<br>
use Sys::Virt;<br>
<br>
# Open libvirt connection and get the domain.<br>
my $conn = Sys::Virt->new (readonly => 1);<br>
my $dom = $conn->get_domain_by_name ($ARGV[0]);<br>
<br>
# Get the libvirt XML for the domain.<br>
my $xml = $dom->get_xml_description ();<br>
<br>
# Parse out the MAC addresses using an XPath expression.<br>
my $xp = XML::XPath->new (xml => $xml);<br>
my $nodes = $xp->find <br>
("//devices/interface[\@type='network']/mac/\@address");<br>
my $node;<br>
my @mac_addrs;<br>
foreach $node ($nodes->get_nodelist) {<br>
     push @mac_addrs, lc ($node->getData)<br>
}<br>
<br>
# Look up the MAC addresses in the output of 'arp -an'.<br>
my @arp_lines = split /\n/, `arp -an`;<br>
foreach (@arp_lines) {<br>
     if (/\((.*?)\) at (.*?) /) {<br>
         my $this_addr = lc $2;<br>
         if (list_member ($this_addr, @mac_addrs)) {<br>
             print "$1\n";<br>
         }<br>
     }<br>
}<br>
<br>
sub list_member<br>
{<br>
     local $_;<br>
     my $item = shift;<br>
     foreach (@_) {<br>
         return 1 if $item eq $_;<br>
     }<br>
     return 0;<br>
}<br>
<br>
<br>
</blockquote></div>