How Do You Give Internet Access to a Linux Guest of Oracle VirtualBox Running on a Windows Host?

Problem scenario:
You created a new Linux CentOS 7.x guest server using Oracle VirtualBox on a Windows host.  Your Windows machine has Internet access.  From the Linux Guest you try to ping a 8.8.8.8 but you get this message "connect: Network is unreachable."

How do you give the Linux guest Internet access?

Possible Solution #1
1.  Using the GUI of the Oracle VirtualBox guest server, go to Devices -> Network Settings.  If you see the drop down for "Attached to:" as "Internal Network" change it to "NAT."  If you just installed Oracle VirtualBox, this step (#1) is probably unnecessary.
2.  Back up this file: /etc/sysconfig/network-scripts/ifcfg-enp0s3
3.  Modify this file "/etc/sysconfig/network-scripts/ifcfg-enp0s3" so the "ONBOOT=no" stanza to says "yes."  For example this is the desired stanza:

ONBOOT=yes

4.  Once the file above has ONBOOT=yes, run this command:  service network restart
5.  Now your Linux guest should have Internet access.

Possible Solution #2
1. In Oracle VirtualBox's GUI for the VM, make sure the network setting for "Attached to:" is "NAT".
2. Run a command like this but replace "43" with the octet of your choice:
sudo ifconfig enp0s3 10.0.2.43 255.255.255.0

3. Run a command like this: sudo ip route add default via 10.0.2.2
4. Optional step: You may now use PuTTy to connect the guest machines if you use port forwarding. You can arbitrarily map IP addresses and ports to different IP addresses and ports on the guest VM. See this posting "How Do You Use Putty To Connect To A CentOS Server (A Guest VM running on Oracle VirtualBox on a Windows Host)?" for more information.

Leave a comment

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