VMware Communities
kontiki
Enthusiast
Enthusiast
Jump to solution

How to find IP address of VMs from Linux host

Hi,

Is there any tool that can resolve the IP address of the running VMs from the linux host, when using NAT networking and DHCP ?

I can find them by logging in the VMs, but I need to automatically retrieve these addresses so the scripts in the host won't have to be manually changed when the IPs change.

Thanks

Host: Ubuntu 8.10 64 bit, WS6.5

Reply
0 Kudos
1 Solution

Accepted Solutions
louyo
Virtuoso
Virtuoso
Jump to solution

Probably the easiest solution is to use static IP addresses... That said, what I was trying to say was:

Each (real and virtual)machine has a unique MAC address. If I were to create a (database type) file with each VM's name and MAC address, then I could use nmap or arp commands to obtain the IP address. For example, I create a table and put it in a file like so:

VMName1 00:14:BF:19:45:61

VMName2 00:0E:5C:1A:44:1E

Machine name 3.... etc

then I could run a combination of arp and/or nmap to find the MAC address of active machines and their respective IP addresses. For instance, running:

sudo nmap -sP 10.0.2.0/24

Yields this on my LAN:

Starting Nmap 4.76 ( http://nmap.org ) at 2009-08-14 18:09 EDT

Host 10.0.2.1 appears to be up.

MAC Address: 00:14:BF:19:45:61 (Cisco-Linksys)

Host 10.0.2.99 appears to be up.

MAC Address: 00:10:83:BB:08:99 (Hewlett-packard Company)

Host 10.0.2.130 appears to be up.

MAC Address: 00:0E:5C:1A:44:1E (Motorola BCS)

Host 10.0.2.134 appears to be up.

Nmap done: 256 IP addresses (4 hosts up) scanned in 3.71 seconds

So, now I know that the machine VMName1, with MAC 00:14:BF:19:45:61 has IP address 10.0.2.1 and is my Linksys router.

Just a thought.

View solution in original post

Reply
0 Kudos
13 Replies
dtracey
Expert
Expert
Jump to solution

Hi Kontiki,

What OSes are the guests running?

Dan

kontiki
Enthusiast
Enthusiast
Jump to solution

Hi Dan,

I use a mix of VM OS-s, Win XP and Unix OS-s ( Linux, Solaris,...) .

Thanks

Reply
0 Kudos
dtracey
Expert
Expert
Jump to solution

Hi Kontiki,

Which server is hosting DHCP? I would think the quickest and easiest way would be for the host to query the DHCP server, but the way to do this depends on the OS and configuration...

Alternatively if you are comfortable with Powershell / PowerCLI you could run the following query:

PS> $IPExp = @{ N = "IPAddress"; E = { $_ | Get-VMGuest | select -ExpandProperty ip* } }

PS> Get-VM | Select name, $IPExp

It'll give you output such as this:

Name IPAddress

-


-


BASGHH-WEBP-01 172.23.21.5

BASNPC-SQLL-05 192.168.148.54

TEST-VM-SCOM-03 0.0.0.0

BASSQL-ODBV02 172.23.15.11

TEST-VM-SCOM-04 0.0.0.0

BASCSS-VCAT-01 172.29.7.13

BASGHH-CXAP-01 172.23.21.3

Let me know if you need any further explanation!

Dan

vmroyale
Immortal
Immortal
Jump to solution

Hello.

The vmrun command can be used to obtain the IP addresses of the virtual machines. Check out an example over at Wil's VI Toolkit.

Good Luck!

Brian Atkinson | vExpert | VMTN Moderator | Author of "VCP5-DCV VMware Certified Professional-Data Center Virtualization on vSphere 5.5 Study Guide: VCP-550" | @vmroyale | http://vmroyale.com
Reply
0 Kudos
louyo
Virtuoso
Virtuoso
Jump to solution

Since you are running a Linux host, I would think a simple way would be to build a table of Machine names to MAC addresses and then just do an arp -a and redirect to a file.

Then do a lookup in your script:

arp -a

? (10.0.2.1) at 00:14:bf:19:45:61 on eth0

? (10.0.2.141) at 00:0c:29:9c:66:40 on eth0

If you want a full list of IP addresses and ports on the LAN, nmap will do it.

sudo nmap -T Aggressive -A 10.0.2.0/24

Interesting ports on 10.0.2.141:

Not shown: 995 closed ports

PORT STATE SERVICE VERSION

135/tcp open msrpc Microsoft Windows RPC

139/tcp open netbios-ssn

445/tcp open microsoft-ds Microsoft Windows XP microsoft-ds

2869/tcp open http Microsoft HTTPAPI httpd 1.0 (SSDP/UPnP)

3390/tcp open microsoft-rdp Microsoft Terminal Service

MAC Address: 00:0C:29:9C:66:40 (VMware)

No exact OS matches for host (If you know what OS is running on it, see http://nmap.org/submit/ ).

TCP/IP fingerprint:

Lou

Reply
0 Kudos
dtracey
Expert
Expert
Jump to solution

Hi Kontiki - i've just re-read the post and realise you are running workstation and not ESX!

Therefore you can ignore the powershell bit and have a look at how the vmrun command can pull back the guest ip address!

You could create a vmrun script to use runProgramInGuest run ipconfig & ifconfig on the guests? Or you could have the guests write their IP addresses to a file on startup and use teh vmrun copyFileFromGuestToHost command...

Let me know if this is the way you want to go and i'll see if i can help.

Dan

Reply
0 Kudos
kontiki
Enthusiast
Enthusiast
Jump to solution

Hi again,

Dan, vmroyale - thanks for your assistance, but the problem with vmrun command is that it requires username / password written explicitly in the open, a bit unsecure; that could be my last resort.

Lou, yours seems the way to go. I'm having some issues with arp command though .

When I'm trying to update the table, using hostname and MAC addr, it does not accept it. It works only when I provide* IP address* and MAC addr. Kind of defeats the point of providing only hostname and MAC addr.

Below is an example of Solaris 10 as VM.

sudo arp -s usacosol10 0:c:21:dd:23:5r

SIOCSARP: Network is unreachable

> > sudo arp -s 192.168.51.135 0:c:21:dd:23:5r ## works, but does not help

Whereas with nmap command I get no valid results, ( sudo nmap -T Aggressive -A 192.168.51.0/24 - some verbose non-helpful info ).

Maybe I'm doing something wrong; btw I'm an occasional user of both these commands.

Any more ideas ?

Thanks all.

PS. Lou and vmroyale, your answers are definitely helpful, but I don't see the helpful buttons near your usernames ( software issues, I believe ) . I'll assign points as soon as they're available.

Reply
0 Kudos
wila
Immortal
Immortal
Jump to solution

Hi,

PMJI, but...

Dan, vmroyale - thanks for your assistance, but the problem with vmrun command is that it requires username / password written explicitly in the open, a bit unsecure; that could be my last resort.

Actually if you read the documentation for vmrun then you will see that vmrun doesn't require username/password for VMware workstation....

Your guests do need to have a valid VMware tools package though and you will have to use "-T ws" as a parameter instead of "-T server".

Just running vmrun from the command line will give you a brief screen of help with examples.



--

Wil

_____________________________________________________

VI-Toolkit & scripts wiki at http://www.vi-toolkit.com

| Author of Vimalin. The virtual machine Backup app for VMware Fusion, VMware Workstation and Player |
| More info at vimalin.com | Twitter @wilva
Reply
0 Kudos
kontiki
Enthusiast
Enthusiast
Jump to solution

Actually if you read the documentation for vmrun then you will see that vmrun doesn't require username/password for VMware workstation....

Good to know that I don't have to use the password - nice tip, thanks.

Your guests do need to have a valid VMware tools package though

...the problem is that I don't have tools installed for all the VMs ( solaris for example ) and I'd like not to depend on the tools.

Reply
0 Kudos
louyo
Virtuoso
Virtuoso
Jump to solution

Probably the easiest solution is to use static IP addresses... That said, what I was trying to say was:

Each (real and virtual)machine has a unique MAC address. If I were to create a (database type) file with each VM's name and MAC address, then I could use nmap or arp commands to obtain the IP address. For example, I create a table and put it in a file like so:

VMName1 00:14:BF:19:45:61

VMName2 00:0E:5C:1A:44:1E

Machine name 3.... etc

then I could run a combination of arp and/or nmap to find the MAC address of active machines and their respective IP addresses. For instance, running:

sudo nmap -sP 10.0.2.0/24

Yields this on my LAN:

Starting Nmap 4.76 ( http://nmap.org ) at 2009-08-14 18:09 EDT

Host 10.0.2.1 appears to be up.

MAC Address: 00:14:BF:19:45:61 (Cisco-Linksys)

Host 10.0.2.99 appears to be up.

MAC Address: 00:10:83:BB:08:99 (Hewlett-packard Company)

Host 10.0.2.130 appears to be up.

MAC Address: 00:0E:5C:1A:44:1E (Motorola BCS)

Host 10.0.2.134 appears to be up.

Nmap done: 256 IP addresses (4 hosts up) scanned in 3.71 seconds

So, now I know that the machine VMName1, with MAC 00:14:BF:19:45:61 has IP address 10.0.2.1 and is my Linksys router.

Just a thought.

Reply
0 Kudos
kontiki
Enthusiast
Enthusiast
Jump to solution

These options ( -sP ) of nmap worked great:

>sudo nmap -sP 192.168.51.0/24

... didn't know that, it gave me all the info I needed. With arp command wasn't that lucky ..., no biggie.

I found something else in the meantime,... while searching /etc/vmware directory, I found that the info in the file dhcpd.leases in /etc/vmware/vmnet8/dhcpd/ directory, seems to do the trick as well. I could easily extract the IPs from their respective MAC addresses.

That's the file where WS writes all of its VMs NAT networking info, which ( I think ) gets updated automatically when the guest IPs are changed by the DHCP server. I just tested creating a full clone of a Linux VM, and sure enough the file was updated with the new IP and MAC address.

A snapshot of the file is shown below:

$ more /etc/vmware/vmnet8/dhcpd/dhcpd.leases

lease 192.168.51.120 {

starts 5 2009/08/14 20:20:26;

ends 5 2009/08/14 20:50:26;

hardware ethernet 00:0c:xx:xx:xx:44;

}

lease 192.168.51.121 {

starts 5 2009/08/14 19:55:30;

ends 5 2009/08/14 20:25:30;

hardware ethernet 00:0c:xx:xx:xx:33;

Thanks for your help.

Reply
0 Kudos
Oleg11
Contributor
Contributor
Jump to solution

Try the Advanced IP Scanner 2.3 is a good program, I like the fast and convenient network scanner IP addresses for Windows.

Full details can be found here http://www.advanced-ip-scanner.com

Reply
0 Kudos
WoodyZ
Immortal
Immortal
Jump to solution

Oleg1 wrote:

Try the Advanced IP Scanner 2.3 is a good program, I like the fast and convenient network scanner IP addresses for Windows.

Full details can be found here http://www.advanced-ip-scanner.com

Why on earth would you bump a ~4.5 year old thread to plug a Windows program when the OP is using Linux! Smiley Wink

Reply
0 Kudos