15

If I have a VM (using VirtualBox, for instance) running inside my main OS; how can I identify the virtual interface and IP address (of the VM) from within the original (host) OS?

I thought I could just use ifconfig, ip a, or similar; but no information related to the connected VM is displayed. Although it shows the main (host) OS has been assigned 192.168.1.104 via wlan0.

However, if I run one of those commands from inside the VM, I can confirm that it's currently active @ 10.0.2.15 via eth0.

voices
  • 1,252
  • 3
  • 15
  • 30
  • 7
    If you use _NAT_ mode for network emulation (default), it setups private network within VirtualBox which is not visible externally. You'll need _bridged_ or _host-only_ network configuration... – myaut Mar 12 '17 at 12:28
  • 1
    @myaut Ah. Okay, I thought it was *bridged* by default. But, even despite *NAT*; if the VM is receiving it's LAN connection, and it's route to the internet, from the main host; surely, the main host must have some kind of record of that link in the IP chain. Because it's accommodating what is effectively another system; forwarding packets back and forth, and that sort of thing. Right? – voices Mar 12 '17 at 14:32

4 Answers4

10

Virtualbox includes a tool called VBoxManage. This tool can access information about the guest OS.

In this example (Windows 10, in a PowerShell window), I want to find the IP of my VM called DS201:

PS C:\Program Files\Oracle\VirtualBox> .\VBoxManage.exe guestproperty get DS201 "/VirtualBox/GuestInfo/Net/0/V4/IP"
Value: 10.0.2.15

(It works the same in Linux and Mac OS X as it does in Windows)

Documentation about the capabilities of VBoxManage can be found at https://www.virtualbox.org/manual/ch08.html.

Tim Kennedy
  • 19,369
  • 4
  • 38
  • 58
2

FOR NAT MODE (per comments) from the manual subsection on NAT mode virtual networking

To your comment that the 'host must ... record ... the IP chain' it's VirtualBox, not the host as such, that does this:

The network frames sent out by the guest operating system are received by VirtualBox's NAT engine, which extracts the TCP/IP data and resends it using the host operating system. To an application on the host, or to another computer on the same network as the host, it looks like the data was sent by the VirtualBox application on the host, using an IP address belonging to the host. VirtualBox listens for replies to the packages sent, and repacks and resends them to the guest machine on its private network.

To your original Q, it is only VirtualBox that knows about the guest's simulated address:

The virtual machine receives its network address and configuration on the private network from a DHCP server integrated into VirtualBox. The IP address thus assigned to the virtual machine is usually on a completely different network than the host. As more than one card of a virtual machine can be set up to use NAT, the first card is connected to the private network 10.0.2.0, the second card to the network 10.0.3.0 and so on. If you need to change the guest-assigned IP range for some reason, please refer to Section 9.11, “Fine-tuning the VirtualBox NAT engine”.

dave_thompson_085
  • 3,790
  • 1
  • 16
  • 16
1

@Tim Kennedy's answer is the way to go, but for a bridged linux guest (Fedora), I had to install the guest additions to be able to see the properties from the host, so it is a bit of a chicken and egg problem.

  1. On the host, set the VBoxGuestAdditions.iso as one of the guest's CDs.
  2. Boot the guest.
  3. Log in the VM (you need the IP if it's headless).
  4. Install kernel-devel if it is not there.
  5. Mount the CD (/dev/sr?)
  6. From the CD, run VBoxLinuxAdditions.run as root. The VM will reboot.

From now on, running:

VBoxManage guestproperty get YourVmName /VirtualBox/GuestInfo/Net/0/V4/IP

on the host gives:

Value: X.Y.Z.T

Remember to install the guest additions after you update the guest's kernel and before you reboot it. This can be done with:

$ sudo /sbin/rcvboxadd quicksetup <new kernel version (e.g. 5.13.9-200.fc34.x86_64)>

Quel Qun
  • 11
  • 2
0

If Windows is your guest system, then with VirtualBox Guest Additions installed

  1. Click the Start button, type cmd.exe and hit Return to launch the Windows command line.

  2. Then paste and run:

    "c:\Program Files\Oracle\VirtualBox Guest Additions\VBoxControl.exe" guestproperty get "/VirtualBox/GuestInfo/Net/0/V4/IP"

  • Windows isn't the host OS - you can see that with the OP's comment, "_I thought I could just use `ifconfig`, `ip a`, or similar_" – roaima Dec 15 '17 at 10:28
  • Other people like me might find this question useful when their guest OS _is_ Windows. – Lars Blumberg Dec 15 '17 at 10:33