[CentOS-virt] Extract ip address from a kvm guest

Mark Pryor tlviewer at yahoo.com
Sat Apr 23 13:32:49 EDT 2011



--- On Sat, 4/23/11, carlopmart <carlopmart at gmail.com> wrote:

> From: carlopmart <carlopmart at gmail.com>
> Subject: [CentOS-virt] Extract ip address from a kvm guest
> To: centos-virt at centos.org
> Date: Saturday, April 23, 2011, 8:07 AM
> Hi all,
> 
>   Somebody knows how can I extract/know an ip address
> used by a kvm 
> guest using a script?? For example I have the following
> guests:
> 
> [root at kvmsrv01 bin]# virsh list --all
>   Id Name           
>      State
> ----------------------------------
>    1 linclunode01     
>    running
>    2 linmgmt       
>       running
>    5 win7desktop       
>   running
> 
> 
>   I know that linclunode01 has 172.25.50.1 as ip
> address, linmgmt has 
> 172.25.50.2 and so on. But suppose that i don't know which
> ip address is 
> used by win7desktop guest. The real fqdn for win7desktop is
> 
> win7.local.net. How can I know its real ip using a script
> (bash, python, 
> etc)?? I don't use a dhcp or dns server on this network.

If you have an http server on the local network:

Inside the VM guest:

------------ /etc/rc.local ------------
wget --spider http://192.168.1.1/favicon.ico?sl6bs?ga-p45
------------ snip ---------

where the web server is at 192.168.1.1, Virt host is ga-p45, and the VM guest is sl6bs.

In the server logs I see:
$ sudo tail -n 175 /var/log/apache2/local_log | grep fav
192.168.1.224 - - [23/Apr/2011:10:10:02 -0700] "HEAD /favicon.ico?lucidpv?ga-p45 HTTP/1.0" 200 296
192.168.1.155 - - [23/Apr/2011:10:10:10 -0700] "HEAD /favicon.ico?centbs?ga-p45 HTTP/1.0" 200 296
192.168.1.183 - - [23/Apr/2011:10:10:10 -0700] "HEAD /favicon.ico?sl6bs?ga-p45 HTTP/1.0" 200 296


-- 
Mark


More information about the CentOS-virt mailing list