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: (NAT adapter)
enp0s8: (Host-Only adapter)

I can connect to my VirtualBox from my host machine:


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:

UUID=UUID HERE (sorry I cannot copy from my guest host yet, no Guest Additions and it was too long)

Why can't my guest connect to the internet?

4 Answers 4


As Gasim said:

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

# Note this was set to no

then reboot the machine.

  • 8
    also reboot after these steps
    – arahant
    Sep 27, 2017 at 21:21
  • 9
    Thanks, this awnser solved my problems. ONBOOT=yes did it for me, I didn't need the lines DNS1 and DNS2. Mar 24, 2018 at 10:58
  • Thanks @Tim Pizey You save my day. :) Mar 15, 2019 at 19:09
  • yes, as @SeanieO'Leary said. Only ONBOOK=yes was also needed for me. May 3, 2019 at 20:25
  • the beauty of linux
    – Ed_
    May 25, 2020 at 0:51

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:

  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
  • 3
    This was my issue with VirtualBox and CentOS7. Checking the "Automatically connect" option fixed my issue. Thanks for the clear instructions... +1
    – swill
    Sep 24, 2019 at 13:34
  • Yep! That worked like a charm. Feb 7, 2020 at 20:40
  • 1
    I am unable to check the option, any idea why? Got to this screen highlighted the checkbox and clicked 'Enter' key. Still remains unchecked
    – Thanthu
    Aug 2, 2020 at 11:24
  • @Thanthu use "Space" key to check.
    – Jing He
    Apr 18, 2021 at 17:32
  • In particular, this is the issue if you installed centos 7 using the text only install, which does not enable the network by default. Saved me time today, thank you. Oct 23, 2021 at 19:33

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:


save it, and once back at the shell


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= and DNS2= 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 (router's address)
    – Gasim
    May 16, 2015 at 11:53
  • That was going to be my next solution
    – td512
    May 16, 2015 at 11:54
  • Doens't help to me Jun 15, 2016 at 12:10
  • Why is this the accepted answer if it doesn't work? Nov 17, 2016 at 17:27

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



  • 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, 2016 at 0:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .