Configure networking for VirtualBox guests

Background

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.

Workaround

There are some common needs and solution when it comes to virtual networking:

  1. Internet in virtual machine or guest OS > Provided by NAT(Network Address Translation)
  2. Virtual machine and host machine reach-ability > Provided by Host Only Networking
  3. Internal virtual machines reach-ability > Provided by Internal Networking
  4. Virtual machine reach-ability from physical network and vice-versa > Provided by Bridge Networking

Internet in virtual machine or guest OS:

  1. Select the VM and right click on it, go to “Settings”.                            
  2. Go to “Network” and “Adapter 1” tab.
  3. By default when you create a virtual machine in Adapter 1 NAT is enabled.
  4. If it is not then Select “Enable Network Adapter” and select “NAT” from the list of “Attached to”.
  5. You need not to do anything in your OS network card, it will get an IP automatically will allow you to access internet.
  6. Login to the guest OS, in this case Oracle Linux 7
  7. Your network might not start automatically, if it is then choose “connect automatically” from OS NIC setting.
  8. Run the command “ifconfig” to show the IP assigned to the NAT NIC.
  9. The IP above is 10.0.2.15 which is the IP assigned to the NIC enp0s3 when the NAT is enabled.
  10. Run the ping to www.google.com.                                                          

Virtual machine and host machine reach-ability:

  1. Shutdown your VM
  2. Go to Settings  > Network > Adapter 2
  3. Select “Enable Network Adapter”
  4. Select “Host Only Adapter” from the list of “Attached to”.                        
  5. Start your VM
  6. Go to network settings and connect the NIC if not automatically connected.
  7. Run the “ifconfig” to see the IP assigned.                                             
  8. The IP assigned to the second NIC enp0s8 is 192.168.56.101.(Host Only IP block is 192.168.56.*)
  9. Now run a ping from your host OS to the above IP.
  10. Determine the VirtualBox Host Only Adapter IP of your host by running ipconfig from your Windows host.
  11. Now run a ping from the virtual machine to the host, generally the host machine Host-Only Adapter IP is 192.168.56.1.

Internal virtual machines reach-ability:

  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.
  2. Shutdown your VM.
  3. To check the this you need to have two or more VM. You can clone the existing one to have another one. See how to clone here
  4. Go to Settings  > Network > Adapter 3
  5. Select “Enable Network Adapter”
  6. Select “Internal Network” from the list of “Attached to”.                      
  7. Start the VM and connect the new NIC attached if not automatically connected.
  8. No IP is assigned to Internal Network automatically, you should configure one by yourself.(Generally assign 192.168.1.*)                                                                                           
  9. Start the second VM that was cloned earlier.
  10. Add the NIC from VirtualBox Manager network settings.
  11. Assign an IP to the NIC enp0s9. (Generally assign 192.168.1.*)
  12. Try to ping the from the VMs, if everything is OK you will be able to ping.
  13. Try to ping the assigned IP from the host machine, it will fail.

Virtual machine reach-ability from physical network and vice-versa:

  1. With this networking mode the virtual machine can to talk to physical network and devices from physical network can reach the virtual machine.
  2. Shutdown your VM.
  3. Go to Settings  > Network > Adapter 4
  4. Select “Enable Network Adapter”
  5. Select “Bridge Network” from the list of “Attached to”.
  6. 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.
  7. Start the VM and connect the new NIC attached if not automatically connected.
  8. Run the “ifconfig” to see the assigned IP by the wireless router DHCP.
  9. The IP 192.168.1.105 assigned to the Bridge Adapter enp0s10.              
  10. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.