How do I find the IP address of a virtual machine using VMware Fusion?

19

9

Can I determine the IP of a virtual machine using VMware Fusion without actually entering the operating system running on the virtual machine? I'm looking for a menu option, command line, or otherwise that I can issue against the virtual image with the VMware Fusion Software itself.

Thanks - Adron

Adron

Posted 2011-12-31T00:42:44.477

Reputation: 313

It's amazing that vmware doesn't make this drop-dead obvious and easy like other vms! Cheers for the avahi answer, and nmap if you're desperate, but still - Big fail, VMware! – nealmcb – 2015-02-08T04:55:39.733

If you know the MAC address of the virtual machine NIC you could always try to leverage your host machine's ARP cache, or reverse ARP. – ta.speot.is – 2011-12-31T00:59:50.187

Answers

1

Short Answer: No

Long Answer: No but maybe

An IP address is purely the responsibility of an OS. Therefore, the virtual framework that holds the OS has no idea about the TCP/IP stack within unless there are symbiotic additions to the framework such as Hyper-V and VMware's additional guest tools (thanks to todda.speot.is in the comments below). It's not much different than wanting to browse the files on a VM without starting it up first.

Technically, if the VM relies on DHCP, you could search your DHCP server (likely your LAN's router) for the last lease that was handed out to the MAC address of the virtual NIC to get a good idea of what the IP would probably be the next time it launches. That's assuming that same IP wasn't handed out to another device in between when you looked at the lease history and when the VM started up.

Wesley

Posted 2011-12-31T00:42:44.477

Reputation: 4 359

1Argh. I was hoping that VMware had some hooks into the OS that would provide that. :( I have no access to the corporate DHCP, thus have no idea since I don't have access to the actual OS either. – Adron – 2011-12-31T00:47:50.353

A hypervisor can hook in and get the IP address, Hyper V does it with its Guest Additions. And it seems some flavours of VMware will tell you, too http://kb.vmware.com/Platform/Publishing/images/1006098.JPG - but as WesleyDavid said, it's not really the hypervisor's responsibility to worry about this.

– ta.speot.is – 2011-12-31T00:58:45.087

48

VMWare provides, not surprisingly, a built in tool for this, vmrun. It's under /Applications/VMware Fusion.app/Contents/Library/vmrun although it has moved around in other Fusion releases a bit.

 vmrun list
    Total running VMs: 1
    .docker/machine/machines/myvm.vmx

  vmrun getGuestIPAddress ~/.docker/machine/machines/myvm.vmx
    172.16.213.128

dch

Posted 2011-12-31T00:42:44.477

Reputation: 581

7This should be the accepted answer. Worked perfectly. – Michael Potter – 2016-02-17T19:03:59.067

2Nice! vmrun is in my Mac's PATH by default, so vmrun getGuestIPAddress "$(vmrun list | grep vmx)", include the quotes! – Big Rich – 2017-10-26T09:59:24.420

Apparently VMWare Tools need to run in the VM. (Fusion V8.5) – Laryx Decidua – 2018-09-04T09:44:06.003

10

Here's a tip in case it helps anyone. Install avahi-daemon on the VM. This allows you to connect via hostname vmname.local, where vmname is the name of your virtual machine. In my case, the VM's name is baremetal and on the host I can run:

ssh baremetal.local

No need to know the VM's IP. :)

berto

Posted 2011-12-31T00:42:44.477

Reputation: 211

1Nice idea but what about VMs that run operating systems where avahi-daemon is not available? Windows for instance comes to mind... :-) – Laryx Decidua – 2014-09-01T09:18:29.293

4

It is possible -- at least, in the common case, where NAT-style network is configured for the guest. Because VMWare is providing the NAT-ing, it ought to be able to tell us, what addresses it is currently NAT-ing for. Something like vmrun list should be outputting this information. That it does not is a flaw...

But, in any case, here is how one can find out anyway. First, run ifconfig on your Mac (perhaps, ipconfig would do the same on Windows, but I haven't tested it). This will list all network interfaces on the machine -- both physical and virtual. Look for the vmnet-ones. On my Mac this produces:

% ifconfig | grep -A2 ^vmnet
vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 00:50:56:c0:00:01 
inet 192.168.82.1 netmask 0xffffff00 broadcast 192.168.82.255
vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 00:50:56:c0:00:08 
inet 192.168.123.1 netmask 0xffffff00 broadcast 192.168.123.255

So, my guest's IP is on either one of these two VM private networks: either 192.168.82.0/24 or 192.168.123.0/24. On your host there may be just one, lucky you, or more than two -- we need to check them all. Here is a very simple tcsh-script, entered directly on command-line, that did it for me. It attempts to ping each address in all of the class-C private networks managed by vmnet and ends, when a ping succeeds. The -W 500 option tells ping to wait only half a second for a response (could, probably, use even less), and the -c 1 tells it to send exactly one packet:

% set i=2
% while ( $i < 255 )
while? ping -W 500 -c 1 192.168.82.$i && break
while? ping -W 500 -c 1 192.168.123.$i && break
while? @ i++
while? end

The above little script ran for some time listing all the unsuccessful attempts to reach the non-existent addresses:

PING 192.168.82.2 (192.168.82.2): 56 data bytes

--- 192.168.82.2 ping statistics ---
1 packets transmitted, 0 packets received, 100.0% packet loss
PING 192.168.123.2 (192.168.123.2): 56 data bytes
...

Until it finally succeeded and finished:

64 bytes from 192.168.123.130: icmp_seq=0 ttl=64 time=0.307 ms

--- 192.168.123.130 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss

Voilà, I was able to ssh into my guest:

% ssh 192.168.123.130
Password:

Now, I only had a single guest running -- so the first IP-address to respond to a ping was the right one. If you run multiple guests at once, you may need to use the same or similar ping command to build a list of all such valid private IP-addresses and then try them all until you get into the correct guest...

(And, maybe, .130 is a good guess for NAT-based addresses anyway. But I can't say for sure.)

Mikhail T.

Posted 2011-12-31T00:42:44.477

Reputation: 419

1With nmap you find the up IPs faster ;-) nmap -sP 192.168.123.* – Robert Reiz – 2015-01-21T12:12:28.583

4

As Mikhail T. said, "Because VMWare is providing the NAT-ing, it ought to be able to tell us, what addresses it is currently NAT-ing for." Indeed it does:

In my VMware Fusion 6 installation, the vmnet-dhcpd daemon writes its leases to the files /var/db/vmware/vmnet-dhcpd-vmnetX.leases, where "X" is 1 and 8. Empirically :-) I established that it is vmnet8 that I should look for. Here is an excerpt from the lease file /var/db/vmware/vmnet-dhcpd-vmnet8.leases:

lease 192.168.177.129 {
    starts 1 2014/02/17 09:34:19;
    ends 1 2014/02/17 09:36:56;
    hardware ethernet 00:0c:29:2b:2b:10;
    client-hostname "ubuntu";
}

The client-hostname is the name of the VM and the number after the word lease is its IP. You can parse these entries or just simply look at the most recent ones. Make sure the lease you are looking at is still valid.

Laryx Decidua

Posted 2011-12-31T00:42:44.477

Reputation: 193

2

My solution to this was:

Once you have VMware tools installed, configure sharing, so that you can access a folder (any folder) from CentOS. Then, modify /etc/sysconfig/network-scripts/ifup-post to append your current date & ip address to a file in this shared folder.

How to do this:

Modify: /etc/sysconfig/network-scripts/ifup-post

add this before the last line of ifup-post ("exit 0"):

date >> /path/to/shared/folder/guest_ip.log
ifconfig >> /path/to/shared/folder/guest_ip.log

This will append your guest_ip.log with the date and return value of ifconfig each time the network comes up.

In my case, I decided to grep for a prefix of 192 on my ip address, since i know that between my home and work, it is always 192. This can be done by adjusting the above as follows:

date >> /path/to/shared/folder/guest_ip.log
ifconfig | grep 192 >> /path/to/shared/folder/guest_ip.log

Mr.BassHatt

Posted 2011-12-31T00:42:44.477

Reputation: 21

"so that you can access a folder (any folder) from CentOS.". What about those people who 1) use other Linux distributions, 2) use UNIX operating systems other than Linux, 3) use non-Unix operating systems such as Windows, ... in their VMs? :-) – Laryx Decidua – 2014-09-01T09:20:48.193

1

Run in VM console ipconfig (if VM is Windows) or ifconfig (if VM is Linux).

IP of eth0 is the IP address that you are looking for.

VM user

Posted 2011-12-31T00:42:44.477

Reputation: 11

The original question was "without actually entering the operating system running on the virtual machine?" This might have escaped your attention. – Laryx Decidua – 2014-09-01T09:22:10.813

It might not answer the question, but I ended up here with a slightly different question and it was helpful. – jamie-wilson – 2016-06-01T20:53:48.200

1

I had the same issue while running VMPlayer on Ubuntu 15.04. My virtual machine was set to NAT, and though I could determine its ip address by logging into the gui and running ifconfig in the VM, I could't ping or ssh into it.

Turns out when VMPlayer installed, it didn't enable dhcp on the vmnet1 and vmnet8 adaptor. Solution was to use the ubuntu gui to edit the network connections with "Edit Connections". Find vmnet1 under ethernet, and hit the edit button. Under IPv4 settings, enable DHCP, save and reboot.

Now if you run ifconfig on the command line, you'll notice that the vmnet1 has a ip address. SSHing into the nat-ed VM from the host now works as well.

Atifm

Posted 2011-12-31T00:42:44.477

Reputation: 111

0

From the manpages of vmrun (version 1.14.4 build-3204469):

getGuestIPAddress        Path to vmx file     Gets the IP address of  the guest
                         [-wait]

However, keep in mind that in order for this to work the VMware Tools suite should be installed in the guest OS and this step cannot be accomplished without logging to the guest OS. You can install the tools in a "base image" and create new images from it via cloning. Then you can use the above command to get the IP address of the newly created VMs.

pldimitrov

Posted 2011-12-31T00:42:44.477

Reputation: 111

0

arp -a| grep vmnet 
? (172.16.65.132) at 0:c:29:83:1:e0 on vmnet8 ifscope [ethernet]

Mohammad Shahid Siddiqui

Posted 2011-12-31T00:42:44.477

Reputation: 271