42

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?

69

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  
  • 3
    also reboot after these steps – arahant Sep 27 '17 at 21:21
  • 5
    Thanks, this awnser solved my problems. ONBOOT=yes did it for me, I didn't need the lines DNS1 and DNS2. – Seanie O'Leary Mar 24 '18 at 10:58
  • Thanks @Tim Pizey You save my day. :) – user3337635 Mar 15 at 19:09
  • yes, as @SeanieO'Leary said. Only ONBOOK=yes was also needed for me. – saw-monster May 3 at 20:25
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

  • 5
    Adding 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 May 16 '15 at 11:53
  • That was going to be my next solution – td512 May 16 '15 at 11:54
  • Doens't help to me – Nikita Koksharov Jun 15 '16 at 12:10
  • Why is this the accepted answer if it doesn't work? – forgivenson Nov 17 '16 at 17:27
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

  • 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 Dec 12 '16 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.