In the virtual machines settings created with VirtualBox, you can see that network adapters can be connected to the network in different ways.
By default, virtual machines are configured to access the network through NAT mode.
This network access mode allows the virtual machine to access the network and the Internet without creating conflicts in your network.
Indeed, using NAT mode, IP addresses will be distributed to virtual machines by VirtualBox and not by the DHCP server of your network.
If you wish, you can change the type of network card that will be emulated by VirtualBox for the virtual machine.
This can resolve compatibility issues with some operating systems or some Live CDs that don't support the default one.
The only problem with NAT mode is that you will not be able to access the services of your virtual machine from a computer on your network because your virtual machine will be behind a gateway (emulated by VirtualBox).
To prove it, we installed a web server (thanks to WAMP) on our virtual machine.
Once the web server is started, Windows asks us if we want to allow access to our web server from the network.
We click on Allow access.
In our virtual machine, we have access to our local site.
In order for the web server to be accessible from the network, we click on "Put Online" in the WAMP menu.
As you can see, our physical computer has the IP address "10.0.0.5" and the subnet mask "255.255.255.0".
So our PC is on the network : 10.0.0.x.
While the virtual machine is on the 10.0.2.x network and is behind the "10.0.2.2" gateway.
So, we can not access the server of our virtual machine by directly typing its IP address.
To solve this problem, the easiest way is to use the "Bridged Adapter" network access mode.
But, you can also configure the port forwarding of the virtual gateway created by VirtualBox to access the web server of your virtual machine from any PC on the network.
To do this, return to the network settings of your virtual machine and click : Port Forwarding.
The "Port Forwarding Rules" window appears.
Click on the + icon on the right.
To create a new rule, you will need to specify :
Click OK to validate this rule.
Now, we can access the web server of our virtual machine using :
If you display PHP info (via phpinfo phpinfo), you will see that :
With VirtualBox, you can also create additional NAT networks.
However, by default, there is none created.
To create a new NAT network, go to the "File -> Preferences" menu.
Then, click on "Network" and then on the + icon.
By default, your new NAT network will be named : NatNetwork.
To configure it, select it and click on the gear icon.
For each NAT network, you will be able to choose :
In this case, you will be able to redirect IPV4 and/or IPv6 ports.
This is our new NAT network.
In the settings of your virtual machine, return to the "Network" section and select :
As you can see, our virtual machine has received an IP address that matches the previously configured network ID "10.0.3.0/24".
For promiscuous mode, it's best to disable it (deny) to not slow down the network speed for your virtual machine.
Enabling promiscuous mode is only useful for analyzing network traffic with sniffers.
The "Bridged Adapter" mode allows you to virtually place your virtual machine in your physical network.
In other words :
When you select the "Bridged Adapter" mode, VirtualBox will allow you to select which network interface it will use to connect this virtual machine to the desired physical network.
In our case, our computer has 2 network interfaces (network cards) :
If you don't know which network adapter to select, go to the Windows Control Panel to view your network connections.
To display them, you have 2 possibilities :
In short, as you can see below, our Ethernet network card is connected to the network, while the Wi-Fi card is not connected at the moment.
So, we selected the "Intel(R) Ethernet Connection (2) I219-LM" network adapter in the network settings of our virtual machine.
Now, our virtual machine has received an IP address from the DHCP server present in our real router.
We can therefore access the web server of our virtual machine as if it were on a physical machine of our network.
This time, the IP address of the server (SERVER_ADDR) corresponds to the IP address used to access our web server and the IP address of the client (REMOTE_ADDR) corresponds to our local IP address.
® InformatiWeb.net 2008-2020 - © Lionel Eppe - All rights reserved.
Total or partial reproduction of this site is prohibited and constitutes an infringement punishable by articles L.335-2 and following of the intellectual property Code.