0

I need to access one of my VirtualBox guest machine via ssh where the host machine is remote and is only accessible via ssh. The guest is configured with DHCP and hence the IP changes on each reboot. Is there any command to find the IP's of each guest machine from the host machine?

I used the following command. But it shows limited information:

    VBoxManage guestproperty enumerate "CHICAGOVPN"
Name: /VirtualBox/HostInfo/VBoxVerExt, value: 4.1.12_Ubuntu, timestamp: 1379492552119809000, flags: TRANSIENT, RDONLYGUEST
Name: /VirtualBox/HostGuest/SysprepExec, value: , timestamp: 1379492552118930000, flags: TRANSIENT, RDONLYGUEST
Name: /VirtualBox/HostGuest/SysprepArgs, value: , timestamp: 1379492552119058000, flags: TRANSIENT, RDONLYGUEST
Name: /VirtualBox/HostInfo/VBoxRev, value: 77245, timestamp: 1379492552119892000, flags: TRANSIENT, RDONLYGUEST
Name: /VirtualBox/HostInfo/VBoxVer, value: 4.1.12, timestamp: 1379492552119750000, flags: TRANSIENT, RDONLYGUEST
2
  • 3
    Have your guests perform a dynamic dns update?
    – Zoredache
    Sep 19, 2013 at 5:51
  • my requirement is to get a command to find the ip address of the guest machines from host console Sep 19, 2013 at 6:05

2 Answers 2

6

If you have the guest additions installed, the IP address should be available in the Net group of properties when it is assigned by VirtualBox itself (NAT/host-only mode):

vboxmanage guestproperty get "VM_NAME" "/VirtualBox/GuestInfo/Net/0/V4/IP"

This command should return something like this:

Value: 192.168.0.54

So you can extract the address from it and use it with ssh:

VM_IP=$(vboxmanage guestproperty get "VM_NAME" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print($2); }')
ssh -l USERNAME $VM_IP

If the guest and its network adapter is in bridged mode it probably gets an IP address from DHCP server running in your network (if not set statically) and the above command doesn't work. I would then try to guess it from local ARP table (as David mentioned) with help of this command:

vboxmanage showvminfo VM_NAME --details

Output:

Name:            VM_NAME
Guest OS:        Ubuntu
UUID:            ff66cb62-f92d-447e-8238-2f76c58bc7bf
...
NIC 1:           MAC: 080027F8A346, Attachment: Internal Network 'intnet', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0
NIC 2:           disabled
...

Take the MAC address from the related network interface (in this example NIC 1):

vboxmanage showvminfo VM_NAME --details 2>&1 | grep 'NIC 1:' | sed -re 's/.*MAC: (.+), Attachment.*/\1/' -e 's/(\w{2})/\1:/g' -e 's/:$//'

Output:

08:00:27:F8:A3:46

Finally, check ARP table for that MAC address and assigned IP. Keep in mind that you don't have to find anything if there is no traffic from/to that guest as the related entry may timeout. If you run this command after you start the guest it's very likely there will be such entry due to DHCP handshake between the guest and DHCP server.

5
  • Following is the output I got:root@VirtualBox:~# VBoxManage guestproperty get "CHICAGOVPN" "/VirtualBox/GuestInfo/Net/0/V4/IP" No value set! Sep 19, 2013 at 6:28
  • How is your guest configured in regards of networking? NAT/bridged/host-only?
    – dsmsk80
    Sep 19, 2013 at 7:39
  • for networking its bridged Sep 19, 2013 at 9:00
  • dsmsk80, I was not able to get the IP the way you suggested. So I changed the IP's to static and thats fine for now. Thanks Sep 20, 2013 at 9:08
  • 1
    It seems that the Guest Additions are required for that.
    – maxdec
    Sep 1, 2014 at 11:53
3

This should do it for you.

VBoxManage guestproperty get "CHICAGOVPN" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $2 }'
2
  • The output of the command is "No value set!" Sep 19, 2013 at 6:31
  • Sorry about that, I guess this is normal behavior since it was assigned using DHCP in bridged mode. Do you know the range of addy's the DHCP server is issuing? Maybe you can see it in the ARP table? Sep 19, 2013 at 7:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.