Connecting Windows to Virtual Machines in VirtualBox
Posted on Dec 6, 2016 in VirtualBox by Amo Chen ‐ 2 min read
Since Windows uses virtual network adapters to achieve VirtualBox’s network functionality, connecting from Windows to a virtual machine in VirtualBox requires some simple setup. This setup is known as “Port forwarding.”
First, we need to know the IP address of the VirtualBox virtual network adapter.
You can enter the following command in the command line:
ipconfig
This will display the current settings for all network interfaces. We’re looking for Ethernet adapter VirtualBox Host-Only Network
.
Here’s how it looks:
The IP address of this virtual network adapter is the one we need. In the image above, it’s 192.168.56.1. Take note of it, as we’ll use this IP soon.
Next, select the virtual machine you want to connect to and click on “Settings” to configure the network.
Then select “Network” on the left, and you’ll find “Port Forwarding” at the bottom. This is what we’re interested in!
Clicking inside will bring up the following screen.
The explanation for the image above is as follows:
- “Name” can be set as you like.
- “Protocol” depends on the service the virtual machine offers, such as SSH or Web, which usually use the TCP protocol.
- “Host IP” is the VirtualBox virtual network adapter IP, which we found to be 192.168.56.1.
- “Host Port” is the port on the VirtualBox virtual network adapter that you want to open. You can set this, but ensure no duplicates appear.
- “Guest IP” is the IP of the virtual machine; you can check it after starting the VM. In this example, it’s 10.0.2.15.
- “Guest Port” is the port open within the VM, not the VirtualBox virtual network adapter.
For example, if we have a rule named CentOS-6.3 SSH:
It means all TCP packets sent to port 2222 at 192.168.56.1 will be forwarded to port 22 at 10.0.2.15.
If your virtual machine has an SSH Server installed, you can connect by entering 192.168.56.1:2222
in pietty, allowing you to access port 22 on the VM 10.0.2.15.
As another example, with a rule named CentOS-6.3 Web:
All TCP packets sent to port 8080 at 192.168.56.1 will be forwarded to port 80 at 10.0.2.15.
If your VM has a Web Server installed, you can simply enter the URL http://192.168.56.1:8080 in your browser, easily connecting to port 80 on the VM 10.0.2.15!