How to connect virtual machine to internet connection in VMware/VirtualBox | GoLinuxCloud (2023)

Table of Contents

Advertisement

There are various types of Network Mode available with Oracle VirtualBox and VMware Workstation Player. These two are the most used Virtualization Software by end users for performing R&D and testing.

Before we jump into out main topic on how to connect virtual machine to internet connection, you must have Oracle VirtualBox installed on your environment Server and also you must be familiar with the different types of Network Modes and which one would help us connect to internet using our Linux or Windows OS from the Virtual Machine.

I have written another article with detailed explanation of different network mode available with Oracle VirtualBox and VMware Workstation Player. So in this article I will be very brief and touching only those areas to cover our primary agenda to enable and connect virtual machine to internet connection.

Still installing Linux manually?

I would recommend to configure one click installation using Network PXE Boot Server. Using PXE server you can install Oracle Virtual Machines or KVM based Virtual Machines or any type of physical server without any manual intervention saving time and effort.

ALSO READ: Join Linux to Windows domain using adcli (RHEL/CentOS 7/8)

Below are the Network Modes using which you must use to enable and connect virtual machine to internet connection

  1. Bridged Network
  2. NAT (Network Address Translation)

How Bridged Network Works?

With bridged networking, Oracle VM VirtualBox uses a device driver on your host system that filters data from your physical network adapter. This driver is therefore called a net filter driver. This enables Oracle VM VirtualBox to intercept data from the physical network and inject data into it, effectively creating a new network interface in software.

When a guest is using such a new software interface, it looks to the host system as though the guest were physically connected to the interface using a network cable. The host can send data to the guest through that interface and receive data from it. This means that you can set up routing or bridging between the guest and the rest of your network.

(Video) Configure Network Connectivity and Sharing Between a VirtualBox Host and Guest Virtual Machine

ALSO READ:

How to create or configure network bridge in CentOS / RHEL 7

How NAT Networking works?

Network Address Translation (NAT) is the simplest way of accessing an external network from a virtual machine. Usually, it does not require any configuration on the host network and guest system.

A virtual machine with NAT enabled acts much like a real computer that connects to the Internet through a router. The router, in this case, is the Oracle VM VirtualBox networking engine, which maps traffic from and to the virtual machine transparently.

ALSO READ: Complete Shodan Tutorial | The Search Engine for Hackers

How to select/change Network Mode in Oracle Virtual Box?

  • Assuming you already have a running virtual machine with you, select the virtual machine.
  • Click on Machine from the top panel menu of Oracle Virtual Box and select Settings
  • Next select Network from the left panel menu
  • Choose the Adapter using which you wish to connect virtual machine to internet connection
  • Next from the drop down menu select either Bridged Adapter or NAT
  • Click on Ok and save the settings.

How to connect virtual machine to internet connection in VMware/VirtualBox | GoLinuxCloud (1)

HINT:

The Network Mode can be changed even when the virtual machine is in running state but it is still recommended to perform this activity after powering off the VM.

How to select/change Network Mode in VMware Workstation Player?

  • Again assuming that you already have a running virtual machine
  • Click on Player on the top menu, from the drop down menu select Manage and click on Virtual Machine Settings. Alternatively you can also press "Ctrl + D" to open the virtual machine settings
  • Choose the Network Adapter using which you wish to connect virtual machine to internet connection
  • Next select the Network Mode as NAT or Bridged
  • Click on Ok and save the settings.

How to connect virtual machine to internet connection in VMware/VirtualBox | GoLinuxCloud (2)

HINT:

The Network Mode can be changed even when the virtual machine is in running state but it is still recommended to perform this activity after powering off the VM.

NOTE:

If you are yet to create virtual machine then during the initial setup process you can select Bridged or NAT as the Network Mode for the Virtual network Adapter.

(Video) Connect All VMs Together || Networking Between VMware Workstation Pro and VirtualBox || Lalith Kumar
ALSO READ: How to install Oracle Virtual Box on Linux (CentOS / RHEL 7)

Connect Virtual Machine to Internet Connection using NAT

I would assume that you have selected NAT as the Network mode for your VM's Adapter already.
For NAT it is important that you leave your network settings to use DHCP. There are no manual changes required from the end user here for default settings.

On RHEL/CentOS environment verify your network configuration.Verify the BOOTPROTO directive of your interface configuration file

HINT:

In my case the configuration file name is ifcfg-Ethernet_connection_1, this may vary for your environment so check accordingly.

# egrep BOOTPROTO /etc/sysconfig/network-scripts/ifcfg-Ethernet_connection_1BOOTPROTO=dhcp

Also you can verify the same using nmcli, to list the available network connections

Advertisement

# nmcli con showNAME UUID TYPE DEVICEEthernet connection 1 30cb1359-cb34-4dae-b994-f4b3b39542d7 ethernet enp0s3

Here we have a single connection "Ethernet connection 1", so verify the BOOTPROTO for this connection

# nmcli -p con show "Ethernet connection 1" | grep -i "ipv4.method"ipv4.method: auto

As you see our IPv4 connection is set to auto, for a static ip this will be set to manual

My /etc/resolv.conf file

# cat /etc/resolv.conf# Generated by NetworkManagersearch golinuxcloud.comnameserver 192.168.43.1

On Oracle VirtualBox

IMPORTANT NOTE:

There is a difference how NAT works in VirtualBox and VMware. In Oracle VirtualBox NAT is much like a private network behind a router, the virtual machine is invisible and unreachable from the outside internet. You cannot run a server this way unless you set up port forwarding. But in VMware Workstation Player you can directly connect to your virtual machine using NAT IP Address.

List the available interface and identify the interface for which you have configured NAT as Network Mode in the Settings

(Video) Use a Host Wi-Fi Adapter to Connect a VMware Workstation VM to a Wireless Internet Connection

# ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:d5:cb:b6 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute enp0s3 valid_lft 86385sec preferred_lft 86385sec

In NAT mode, the guest network interface is assigned to the IPv4 range 10.0.x.0/24 by default where x corresponds to the instance of the NAT interface +2. So x is 2 when there is only one NAT instance active. In that case the guest is assigned to the address 10.0.2.15, the gateway is set to 10.0.2.2 and the name server can be found at 10.0.2.3.

You can change the default NAT network for individual virtual machine using below command on your Windows Machine under the home directory of VirtualBox

Advertisement

C:Program FilesOracleVirtualBox>VBoxManage modifyvm "VM name" --natnet1 "192.168.100.0/24"

This command would reserve the network addresses from 192.168.100.0 to 192.168.100.254 for the first NAT network instance of "VM name". The guest IP would be assigned to 192.168.100.15 and the default gateway could be found at 192.168.100.2.

# ip addr show dev enp0s32: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:d5:cb:b6 brd ff:ff:ff:ff:ff:ff inet 192.168.100.15/24 brd 192.168.100.255 scope global dynamic noprefixroute enp0s3 valid_lft 86138sec preferred_lft 86138sec inet6 fe80::a00:27ff:fed5:cbb6/64 scope link valid_lft forever preferred_lft forever

To remove your custom changes for NAT Network

C:Program FilesOracleVirtualBox>VBoxManage modifyvm "VM name" --natnet1 default

Now try to connect virtual machine to internet connection

# ping google.comPING google.com (216.58.196.174) 56(84) bytes of data.64 bytes from maa03s31-in-f14.1e100.net (216.58.196.174): icmp_seq=1 ttl=52 time=37.8 ms64 bytes from maa03s31-in-f14.1e100.net (216.58.196.174): icmp_seq=2 ttl=52 time=35.0 ms^C--- google.com ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 3msrtt min/avg/max/mdev = 35.036/36.428/37.821/1.405 ms

NOTE:

In some cases if you are unable to connect virtual machine to internet connection using NAT then try switching your adapter type. Some times the Adapter Type can be the cause of the problem. In my case for VirtualBox I have to use virtio-net as the Adapter Type

ALSO READ: How to PROPERLY change username on Linux [2 Methods]

How to change Adapter Type in VirtualBox?

  • To change Adapter Type you must power off the respective VM.
  • Next open the Settings of the VM.
  • Navigate to Network and select the Adapter for which you wish to change Adapter Type
  • From the drop down menu of Adapter Type select the preferred type. For me I have used Paravirtualized Network (virtio-net)as IntelPRO/1000 T Server(82543GC) was unable to connect to internet connection.

HINT:

In VMware Workstation Player 15 I could not find any option to change Adapter Type for NAT Networking.

On VMware Workstation Player

Here my VM on VMware Player is on DHCP and is configured as NAT in the VM Settings and I am able to connect to the Virtual Machine from my Windows host laptop.

# ip addr show dev ens332: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:23:13:e0 brd ff:ff:ff:ff:ff:ff inet 192.168.118.128/24 brd 192.168.118.255 scope global dynamic noprefixroute ens33 valid_lft 1472sec preferred_lft 1472sec inet6 fe80::20c:29ff:fe23:13e0/64 scope link valid_lft forever preferred_lft forever

My /etc/resolv.conf which gets automatically populated by NetworkManager

# cat /etc/resolv.conf# Generated by NetworkManagersearch localdomain golinuxcloud.comnameserver 192.168.118.2

My default gateway

(Video) How to connect a virtual machine to internet

# ip route showdefault via 192.168.118.2 dev ens33 proto dhcp metric 100

Check if you are able to connect virtual machine to internet connection

Advertisement

# ping google.comPING google.com (172.217.26.206) 56(84) bytes of data.64 bytes from maa03s23-in-f206.1e100.net (172.217.26.206): icmp_seq=1 ttl=128 time=38.9 ms64 bytes from maa03s23-in-f206.1e100.net (172.217.26.206): icmp_seq=2 ttl=128 time=45.6 ms^C--- google.com ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 3msrtt min/avg/max/mdev = 38.940/42.278/45.616/3.338 ms
ALSO READ: Troubleshoot Packet Fragmentation Issues with Wireshark

Connect Virtual Machine to Internet Connection using Bridged network

For Bridged Network Mode, you can use both DHCP or static IP for your Virtual Machine. I hope you have already changed the network Mode of your Virtual Machine Adapter to Bridgedto be able to connect virtual machine to internet connection.

The steps to use Bridged Network is same for both Oracle VirtualBox and VMware Workstation Player

NOTE:

To have a static IP you must be aware of the subnet, gateway and DNS details which your router is using so that you can use the same for your system's IP configuration.

We will continue to use DHCP for demonstrating this article so verify your network configuration as explained earlier in this article

My new IP Address is now

# ip addr show dev enp0s32: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:d5:cb:b6 brd ff:ff:ff:ff:ff:ff inet 192.168.43.38/24 brd 192.168.43.255 scope global dynamic noprefixroute enp0s3 valid_lft 3486sec preferred_lft 3486sec inet6 fe80::a00:27ff:fed5:cbb6/64 scope link valid_lft forever preferred_lft forever
# ip routedefault via 192.168.43.1 dev enp0s3 proto dhcp metric 100

As you see the IP Address has changed, now I am getting the IP Address directly from the router which should be in the same subnet as from where my laptop is getting the IP as we are using the same router.

ALSO READ: How to analyze LDAP traffic with Wireshark - Tutorial

Below is the IP Address from my laptop using ipconfig command

Wireless LAN adapter WiFi: Connection-specific DNS Suffix . : IPv6 Address. . . . . . . . . . . : 2401:4900:273c:d7cf:979:d5f9:4b34:4958 Temporary IPv6 Address. . . . . . : 2401:4900:273c:d7cf:6cf5:88f5:2444:dadf Link-local IPv6 Address . . . . . : fe80::979:d5f9:4b34:4958%2 IPv4 Address. . . . . . . . . . . : 192.168.43.168 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : fe80::72dd:a8ff:fe0a:8b6f%2 192.168.43.1

So my laptop and virtual machine, both are using 192.168.0.1 as the default gateway.

Check if you are able to connect virtual machine to internet connection

# ping google.comPING google.com (216.58.196.174) 56(84) bytes of data.64 bytes from maa03s31-in-f14.1e100.net (216.58.196.174): icmp_seq=1 ttl=53 time=48.3 ms64 bytes from maa03s31-in-f14.1e100.net (216.58.196.174): icmp_seq=2 ttl=53 time=46.7 ms^C--- google.com ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 2msrtt min/avg/max/mdev = 46.668/47.499/48.330/0.831 ms

NOTE:

(Video) How to Connect VMware Virtual Machine to Entire Physical LAN Network

You must login to the console of the virtual machine using VirtualBox/VMware and restart your network interface using "systemctl restart network" to get new address if you were using NAT or any other Network Mode.

Lastly I hope the steps from the article to connect virtual machine to internet connection on Oracle VirtualBox and VMware Workstation Player using Linux was helpful. So, let me know your suggestions and feedback using the comment section.

FAQs

How to connect a virtual machine to the Internet VirtualBox? ›

How do I enable the Internet on VirtualBox?
  1. Step 1: Ensure the internet connection. ...
  2. Step 2: Turn OFF the Virtual Machine. ...
  3. Step 3: Open network settings of Virtual Machine. ...
  4. Step 4: Enable the Network Adapter. ...
  5. Step 5: Select the Network Device. ...
  6. Step 6: Save Settings and start the Virtual Machine.
May 25, 2021

How do I give my virtual machine access to the Internet? ›

Connect virtual machines to the internet
  1. Open Hyper-V Manager. ...
  2. Select the server in the left pane, or click "Connect to Server..." in the right pane.
  3. In Hyper-V Manager, select Virtual Switch Manager... from the 'Actions' menu on the right.
  4. Under the 'Virtual Switches' section, select New virtual network switch.
Apr 25, 2022

Which VirtualBox network mode allows client to access the Internet? ›

NAT Network

This mode is similar to the NAT mode that you use for configuring a router. If you use the NAT Network mode for multiple virtual machines, they can communicate with each other via the network. The VMs can access other hosts in the physical network and can access external networks including the internet.

Why VMware is not connecting to the Internet? ›

Go to Network and Sharing Center > select Change adapter settings > right-click "VMware Network Adapter VMnet1" (you might see the red x on it) > select Diagnose > do the same for "VMware Network Adapter VMnet8". Some users also reported that disabling the network adapters and then running diagnose could fix the issue.

How do I know if my VM is connected to the Internet? ›

  1. Ping Test. The very first tool I use to check if connected to internet is via ping utility. ...
  2. Check port availability using cat, echo.. There are various tools which can be used to check port availability which I will share in this article. ...
  3. DNS lookup using nslookup, host etc.. ...
  4. Curl. ...
  5. Telnet. ...
  6. Nmap. ...
  7. netcat or nc. ...
  8. wget.
Nov 19, 2019

Can VirtualBox access Internet? ›

A VM accesses the internet through the VirtualBox networking engine. The VirtualBox networking engine creates and manages a private network that the host cannot access. The host can access this private network with additional configuration.

How to enable WiFi on VirtualBox? ›

Using WiFi in a Virtual Machine
  1. Choose Configure from the Virtual Machine menu to open the Virtual Machine Configuration dialog.
  2. Select Network Adapter in the Hardware list.
  3. In the Network Adapter pane, make sure that the Enabled, Connected and Bridged Ethernet options are selected.

What is bridged vs NAT VirtualBox? ›

With bridged networking, the VM is accessible from the network. "NAT" on the other hand shares the hosts network connection by assigning the VMs an IP address from a private network, and translates network requests from the guest. This way the host appears as a single system to the network.

How to connect to Ethernet in VMware? ›

Procedure
  1. Open the virtual machine settings in VMware Remote Console. On Windows, select VMRC > Manage > Virtual Machine Settings. On Linux, select Virtual Machine > Virtual Machine Settings.
  2. Open the Hardware tab and click Add.
  3. Select Network Adapter and click Finish.
Nov 4, 2019

Videos

1. VirtualBox Tutorial - Giving VMs Internal Network, Host PC and Internet Access
(Server Academy)
2. How to Fix VMWare No Internet Issue
(Manny Tutorials)
3. How to fix VMWare no internet connection
(Blog Ternet)
4. How to Connect WiFi Kali Linux Virtual Box | Set up WiFi Connection in Kali Linux VMware Virtual Box
(TeachMeTechnically)
5. VMWare Errors: No network assign to vm while connecting using bridge connection.
(HashTech Coders)
6. Virtualization: VirtualBox VM Networking - Connecting a VirtualBox VM to NAT
(systempeeps)
Top Articles
Latest Posts
Article information

Author: Rueben Jacobs

Last Updated: 04/20/2023

Views: 6034

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Rueben Jacobs

Birthday: 1999-03-14

Address: 951 Caterina Walk, Schambergerside, CA 67667-0896

Phone: +6881806848632

Job: Internal Education Planner

Hobby: Candle making, Cabaret, Poi, Gambling, Rock climbing, Wood carving, Computer programming

Introduction: My name is Rueben Jacobs, I am a cooperative, beautiful, kind, comfortable, glamorous, open, magnificent person who loves writing and wants to share my knowledge and understanding with you.