When you create a virtual machine in VirtualBox the virtual machine or OS needs internet or the virtual machine and your physical machine need to talk to each other or the virtual machine need to be reached from other computers from the network and vice-versa. These are done by VirtualBox networking which uses its logical NIC resides in the host or sometime directly using host computer NIC. The demonstration here will be done for an Oracle Linux 7 guest OS.
Select the VM and right click on it, go to “Settings”.
Go to “Network” and “Adapter 1” tab.
By default when you create a virtual machine in Adapter 1 NAT is enabled.
If it is not then Select “Enable Network Adapter” and select “NAT” from the list of “Attached to”.
You need not to do anything in your OS network card, it will get an IP automatically will allow you to access internet.
Your network might not start automatically, if it is then choose “connect automatically” from OS NIC setting.
Run the command “ifconfig” to show the IP assigned to the NAT NIC.
The IP above is 10.0.2.15 which is the IP assigned to the NIC enp0s3 when the NAT is enabled.
Run the ping to www.google.com.
Select “Host Only Adapter” from the list of “Attached to”.
Go to network settings and connect the NIC if not automatically connected.
Run the “ifconfig” to see the IP assigned.
Now run a ping from your host OS to the above IP.
Determine the VirtualBox Host Only Adapter IP of your host by running ipconfig from your Windows host.
Now run a ping from the virtual machine to the host, generally the host machine Host-Only Adapter IP is 192.168.56.1.
With this networking mode the virtual machines are able to talk to each other on the same host but you can’t reach them from your host machine.
Select “Internal Network” from the list of “Attached to”.
Start the VM and connect the new NIC attached if not automatically connected.
Start the second VM that was cloned earlier.
Add the NIC from VirtualBox Manager network settings.
Try to ping the from the VMs, if everything is OK you will be able to ping.
Try to ping the assigned IP from the host machine, it will fail.
With this networking mode the virtual machine can to talk to physical network and devices from physical network can reach the virtual machine.
Select “Bridge Network” from the list of “Attached to”.
Select the Physical Network Adapter in the list of “Name” to which you are willing to connect your VM. You can have more than one network adapter in your computer so choose wisely which network your VM should connect. In my case i will connect my VM to the Physical Wireless Adapter which connect to the Wireless home router, my other devices like desktop, handhelds are also connected to this network.
Run the “ifconfig” to see the assigned IP by the wireless router DHCP.
The IP 192.168.1.105 assigned to the Bridge Adapter enp0s10.
Try to ping to other computer or devices on the same network and vice-versa, make sure the Firewall on the devices is not preventing the ICMP ping request.
For more information please see the VirtualBox Networking.