How to get IP address assigned to VM running in background

virtualbox

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)?

Best Answer

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.