30

I have VirtualBox set up on a server. It was set up as a Bridged VM, and has an IP address. It's now running in headless mode, started with "VBoxHeadless -s PuppetMaster".

How can I find out what IP the VM is using VBoxManage?

warren
  • 18,369
  • 23
  • 84
  • 135
Jon Haddad
  • 1,372
  • 3
  • 13
  • 20

8 Answers8

22

I could find my Headless VB with the combination of following commands:

# Update arp table
for i in {1..254}; do ping -c 1 192.168.178.$i & done

# Find vm name
VBoxManage list runningvms

# Find MAC: subsitute vmname with your vm's name
VBoxManage showvminfo vmname

# Find IP: substitute vname-mac-addr with your vm's mac address in ':' notation
arp -a | grep vmname-mac-addr

But even easier: in linux, you can connect to the VB:

# Default VirtualBox Listening Port: 3389
rdesktop -N hostingserver:3389

This command will open a shell window, and you'll have direct access to the Headless VB, where you can retrieve your Headless VB IP: ip addr

Alberto
  • 321
  • 3
  • 5
  • I've translated it into golang program https://gist.github.com/mhewedy/352ddb55d4740945d0462df91aece198 I hope I could upload the binary file for ease use by others. – Muhammad Hewedy Jan 19 '20 at 22:20
6

Install guest additions and (assuming linux is the guest) you can run the following:

VBoxManage --nologo guestcontrol yourVirtualMachineName execute --image "/sbin/ifconfig"  --username yourUser --password yourPassword --wait-exit --wait-stdout -- -a
  • 1
    Format changed a bit now, you'll need `VBoxManage --nologo guestcontrol yourVirtualMachineName --username yourUser --password yourPassword run -- /sbin/ifconfig -a` – mike.dld Aug 05 '16 at 13:37
4
VBoxManage guestproperty enumerate {`VBoxManage list runningvms | awk -F"{" '{print $2}'` | grep IP | awk -F"," '{print $2}' | awk '{print $2}'
Scott Pack
  • 14,907
  • 10
  • 53
  • 83
brendan
  • 225
  • 1
  • 3
  • 8
  • Command works for a single VM. -- With multiple VMs filter by VM name, e.g.: `VBoxManage list runningvms | grep vmname | awk ...` – mschuett Jan 04 '13 at 10:22
  • Or we can inquire about a specific VM. e.g. `VBoxManage guestproperty get "/VirtualBox/GuestInfo/Net/0/V4/IP" | cut -f2 -d " "` – Mohnish Aug 02 '17 at 19:17
3

Not sure if VBoxManage can give you that information directly. What you can do is run the following command to see the network card configuration.

VBoxManage showvminfo PuppetMaster | egrep ^NIC

That will if nothing else will provide you with the MAC address, allowing you to find out the actual ip address by other means.

andol
  • 6,938
  • 29
  • 43
3

You can get it directly using this command:

VBoxManage list bridgedifs
slm
  • 7,615
  • 16
  • 56
  • 76
ShawnMilo
  • 155
  • 2
3

From virtualbox.org forum --

VBoxManage guestproperty get <vm-name> "/VirtualBox/GuestInfo/Net/0/V4/IP" | cut -f2 -d " "

Mohnish
  • 168
  • 1
  • 7
  • Nice option. Just noting comment from the forum: "From my testing, it seems the guest properties are only available if the guest VM has the Guest Additions installed." Indeed, I have no guest additions and get "No value set!". – Nagev Nov 22 '22 at 12:28
0

Without guest additions, on a Windows host, and unable to rdesktop into the VM, this is what I did:

Get MAC of virtual machine (WSL Linux) and scan the network:

VBoxManage.exe showvminfo $vmname | grep MAC     # get MAC address
nmap 192.168.178.* -p 22 | grep open -B 5        # Find machines ready to SSH

The scan itself showed me the desired IP, but I can confirm it on the PowerShell, using the MAC I got earlier. For example:

arp -a | findstr -i 08-00-27-9A-49-B6

Output is like:

192.168.178.30        08-00-27-9a-49-b6     dynamic

And that confirms the IP address.

Nagev
  • 580
  • 1
  • 6
  • 10
0

Here is a simple script I put together to get the IP of my Vbox VM.

#!/bin/bash

Knowing my VM is named 'ubuntu22' uuid_raw=$(vboxmanage list runningvms | grep ubuntu) UUID "ubuntu22" {6eac6956-2952-425f-ba20-e865d0970e33} uuid=$(echo $uuid_raw | awk -F' ' '{print $2}' | sed s/{// | sed s/}//) echo "UUID ${uuid}" mac=$(vboxmanage showvminfo --details ${uuid} | grep MAC | awk -F'MAC: ' '{print $2}'| awk -F',' '{print $1}') arp -a | sed s/://g | grep -i $mac


Yields the following output:

UUID 90dcc1dc-e14d-4362-bc7e-c3f58698beb9
? (10.1.50.193) at 080027fd0e63 [ether] on eno1

Dave M
  • 4,514
  • 22
  • 31
  • 30
Gerald
  • 1
  • 1