How to find IP of virtual machine?
Solution 1
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.
Solution 2
@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.
- On the host, set the VBoxGuestAdditions.iso as one of the guest's CDs.
- Boot the guest.
- Log in the VM (you need the IP if it's headless).
- Install kernel-devel if it is not there.
- Mount the CD (/dev/sr?)
- 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)>
Solution 3
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”.
Related videos on Youtube
voices
Updated on September 18, 2022Comments
-
voices over 1 year
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 assigned192.168.1.104
viawlan0
.However, if I run one of those commands from inside the VM, I can confirm that it's currently active @
10.0.2.15
viaeth0
.-
myaut about 7 yearsIf 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...
-
voices about 7 years@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?
-
-
roaima over 6 yearsWindows 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" -
Darren Gill over 6 yearsOther people like me might find this question useful when their guest OS is Windows.