CentOS 7 VirtualBox no internet access

46

23

I am having trouble connecting my CentOS 7 guest to the internet. My VirtualBox Network configuration is as follows:

Adapter 1: NAT; Adapter 2: Host-Only (vboxnet0)

vboxnet0 is connected set up with DHCP with default VirtualBox parameters.

In my CentOS Guest, I commanded ip a and got the following:

enp0s3: 10.0.2.15/24 (NAT adapter)
enp0s8: 192.168.56.102/24 (Host-Only adapter)

I can connect to my VirtualBox from my host machine:

ping 192.168.56.102

can transmit and receive packets.

However, my VirtualBox cannot access the internet:

ping www.google.com

outputs "unknown host www.google.com"

Here is my ifcfg-enp0s3:

TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
IPV4_FAILURE_FATAL=no
IPV6_INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s3
UUID=UUID HERE (sorry I cannot copy from my guest host yet, no Guest Additions and it was too long)
DEVICE=enp0s3
ONBOOT=yes

Why can't my guest connect to the internet?

Gasim

Posted 2015-05-16T11:13:20.407

Reputation: 595

Answers

76

As Gasim said:

Add the following to /etc/sysconfig/network-scripts/ifcfg-enp0s3

DNS1=8.8.8.8
DNS2=8.8.4.4
# Note this was set to no
ONBOOT=yes  

Tim Pizey

Posted 2015-05-16T11:13:20.407

Reputation: 876

3also reboot after these steps – arahant – 2017-09-27T21:21:15.773

5Thanks, this awnser solved my problems. ONBOOT=yes did it for me, I didn't need the lines DNS1 and DNS2. – Seanie O'Leary – 2018-03-24T10:58:18.167

Thanks @Tim Pizey You save my day. :) – user3337635 – 2019-03-15T19:09:26.363

yes, as @SeanieO'Leary said. Only ONBOOK=yes was also needed for me. – saw-monster – 2019-05-03T20:25:06.230

7

Chances are that in /etc/resolv.conf you don't have any nameservers set, in which case you want to do:

vim /etc/resolv.conf

and add:

nameserver 8.8.8.8
nameserver 8.8.4.4

save it, and once back at the shell

do:

sudo reboot now to reboot and you should have internet access

td512

Posted 2015-05-16T11:13:20.407

Reputation: 4 778

5Adding it to resolv.conf didn't work because it was being auto generated by Network Manager, so I added DNS1=8.8.8.8 and DNS2=8.8.4.4 to ifcfg-enp0s3 and it worked. But the weird thing is that, resolv.conf adds my router address as the nameserver and in my Router. My router's DNS are already Google DNS, so I don't know why it doesn't recognize the DNS when I set nameserver 10.0.2.1 (router's address) – Gasim – 2015-05-16T11:53:34.107

That was going to be my next solution – td512 – 2015-05-16T11:54:27.017

Doens't help to me – Nikita Koksharov – 2016-06-15T12:10:16.120

Why is this the accepted answer if it doesn't work? – forgivenson – 2016-11-17T17:27:21.673

3

Network connection is not active by default. You can check this by running the command:

nmcli d

To edit the connection run the following command:

nmtui
  1. Edit a connection
  2. Choose your Ethernet connection
  3. Check the option "Automatically connect" as shown in the pic below:

    nmtui GUI

  4. systemctl restart network

  5. sudo shutdown -r now

Rafael15986

Posted 2015-05-16T11:13:20.407

Reputation: 31

This was my issue with VirtualBox and CentOS7. Checking the "Automatically connect" option fixed my issue. Thanks for the clear instructions... +1 – swill – 2019-09-24T13:34:04.670

Yep! That worked like a charm. – John Fantastico – 2020-02-07T20:40:14.240

0

In VirtualBox for CentOS 7 VM, I faced the same issue.

You dont need to configure these files. The DNS is set via the Network Manager. On the bottom right hand corner if you see the two monitor thingy, just right click on that and connect the network adapter.

Even though you change the resolv.conf file by adding the DNS, the DNS set at your host machine/DNS set by your service provide over rides it.

And the resolv.conf gets updated as follows -

Generated by NetworkManager

search XXX#.XX.comcast.net

nameserver 75.75.76.76

nameserver 75.75.75.75

Shashank Vyas

Posted 2015-05-16T11:13:20.407

Reputation: 1

I am not using GUI. And you can change the DNS if you change the network adapter config files. That's the proper CentOS way. That's because CentOS uses a separate network manager (I think it is called Anaconda) to automatically set IP, DNS, and other network variables for network adapters. – Gasim – 2016-12-12T00:19:13.597