Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I run my Ubuntu instance out of Virtual Box in the background using the following command:

VBoxManage startvm ${VM_NAME} --type headless

The main difference between that and running it through the GUI is that, when I am in the GUI after it starts, I can check ifconfig to see what the IP address is so that I can ssh into it from my terminal on the host and obviously can't do that in the background.

Assuming a dynamic assignment of IP addresses on the network, is there a way to extract the assigned IP to the newly created instance for ssh purposes OR is there a way to ssh into it without knowing the IP (e.g. via a backdoor port on the host)?

share|improve this question

You can use the VBoxManage command to extract the IP address, as shown in this forum post on virtualbox.org:

VBoxManage guestproperty enumerate <vmname>

Unless you have very good reasons, though, you'll want to strongly consider assigning a static IP address to your guest vm. This is possible even though you are probably using DHCP. Just pick an IP address outside the range that your DHCP server allocates.

share|improve this answer
    
that command did not return the IP address – amphibient Aug 20 '13 at 14:01
2  
You need to have the guest additions installed for this to work. – heavyd Aug 20 '13 at 14:42

First at all make sure you have installed VirtualBox Extension Pack or install it if don't.

For example ( for Ubuntu )

> wget http://download.virtualbox.org/virtualbox/4.2.12/Oracle_VM_VirtualBox_Extension_Pack-4.2.12-84980.vbox-extpack
> sudo VBoxManage extpack install ./Oracle_VM_VirtualBox_Extension_Pack-4.2.12-84980.vbox-extpack

or from

https://www.virtualbox.org/wiki/Downloads

After that you can get IP of VM

VBoxManage guestproperty enumerate <_name_of_VM_> | grep IP | grep -o -w -P -e '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
share|improve this answer
    
still doesnt display the IP for me – Josh Nankin Apr 21 '15 at 22:20

I know I'm late to this party, but this will work with VirtualBox 5.0.6.

This uses VBoxManage to grab a list of running virtual machines, queries their properties in a loop, and displays the IP addresses in a pretty way.

#!/bin/bash

for f in $(VBoxManage list runningvms | awk -F\" '{print $2}'); do
      echo "$f:"
      VBoxManage guestproperty enumerate "$f" | grep IP
    done
share|improve this answer
    
explaining a bit more wouldn't hurt – Jakuje Nov 5 '15 at 20:56
    
added more explanation to the post. – Dan Stynchula Nov 5 '15 at 21:06

You can look at the DHCP table in the router, before startup and after and compare them. If the router displays the computer name, that makes it a lot easier of course. This is maybe not a sofisticated solution, but it works.

share|improve this answer
VMNAME="..."; # save ID of VM  in VMNAME variable
vboxmanage guestproperty enumerate $VM_NAME|grep IP|cut -f2 -d,|cut -f2 -d:
share|improve this answer
1  
We’re looking for substantial answers that provide some explanation and context.  Please don’t give just a two-line code answer; explain why your answer is right, ideally with citations.  Answers that don’t include explanations may be removed.  But also, your answer is equivalent to previous answers except for trivial formatting differences.  Please don’t post an answer unless you actually have something new to contribute. – G-Man Dec 26 '15 at 11:48
    
:). u'r welcome .. not at all – Abdennour TOUMI Dec 26 '15 at 12:27
    
@G-Man : if you have thousand accounts , log-in to them , and vote-down.. Unfortunately , i will not delete the answer . – Abdennour TOUMI Dec 26 '15 at 22:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .