61

I have Ubuntu 12.10 on which I installed virtual box on which I setup Centos 6.4 i386. On Ubuntu I have: 3.5.0-17-generic kernel running.

On virtual box I install Centos 6.4 and everything works fine, however when I boot into VM machine, there is only on loopback interface. Nothing else. I tried to manually add ifcfg-eth0 file but nothing happens. On VM settings I have added NAT and HostOnly interfaces but whenever I boot into Centos there is just lo interface. What should I do?

12 Answers 12

56

You need to enable networking during installation. You can do it post install as well. This is a change in the CentOS installation in the 6.x versions which throws a lot of people off, including myself.

Starting with CentOS 6.x you can either opt to have NetworkManager manage your network setups or still do it the old fashion way and set them up manually using /etc/sysconfig/network-scripts/ifcfg-eth0 types of files. Given this is a VM I'd recommend using NetworkManager.

To invoke the connection editor tool do the following:

$ nm-connection-editor

You'll be presented with a GUI like this:

                         ss of conn. editor

From this GUI you'll need to edit the eth0 setup like so:

                         ss of nm #1

                         ss of nm #2

                         ss of nm #3

Without a GUI

If you're attempting to do this on a headless server you can edit the following files and reboot to get your eth0 networking device to come up enabled and acquire an IP address from a DHCP server. Change these 2 options in the file, /etc/sysconfig/network-scripts/ifcfg-eth0:

ONBOOT="yes"
NM_CONTROLLED="no"

References

7
  • 5
    Centos 6.4 "nm-connection-editor not found" ... no GUI running. Headless server. no joy. :(
    – Mojo
    Jul 22, 2013 at 19:10
  • 1
    "Without a GUI" steps worked perfectly, thank you so much!
    – Wildcard
    Jul 29, 2016 at 22:38
  • 2
    The Without a GUI steps threw me off a bit until I checked out the next few answers. In CentOS min, instead of eth0 it is something else, so please update your answer to ifcfg-XXXX. Also, NM_CONTROLLED was not listed and as the others did not specify it I did not add it so that must be the default. Network is up and running now. If you can also update answer to redirect 'NO GUI' guys, or place it above the GUI answer that would be great, as I suspect n/w would be disabled only on min distros, if it is disabled on normal distros, that is questionable as it would befuddle a lot of noobs.
    – killjoy
    Mar 19, 2017 at 14:42
  • @killjoy - what CentOS version are you using. What I showed above was how it was in 2013 when I wrote this up. Things may have changed in newer versions. Also the NM_CONTROLLED is how you can explicitly do this. Hence why I showed it.
    – slm
    Mar 19, 2017 at 14:47
  • @slim - latest 7 version as of the date of the post, in fact some others have different values also. On my work VM, it is '-eno', so yeah I guess it is not a static eth0 as before.
    – killjoy
    Mar 20, 2017 at 15:50
20

Run the command:

$ ip a

This will show the the interfaces. Got to /etc/sysconfig/network-scripts open the corresponding ifcfg file and set on boot to yes. Restart the system and you are down.

By default this is set to no in Centos 7

4
  • 1
    Does it matter if you're running in a VM? Because I've done all of this a bunch of times, and it STILL says the network is unreachable, and I can't install the VirtualBox guest additions without the network, because CentOS doesn't include bzip2 for some retarded reason.
    – MarcusJ
    Dec 15, 2015 at 15:18
  • 1
    To expand on this, you can create a new ifcfg file and name the interface whatever you want with the DEVICE=[name] option so long as you include the HWADDR=[mac address].
    – Centimane
    Feb 16, 2017 at 13:30
  • You also need to change this line: NM_CONTROLLED=no Oct 27, 2017 at 16:40
  • 1
    what do you do if there's no ifcfg- file that corresponds to the device ip a shows?
    – marathon
    Jul 25, 2018 at 22:40
15

Running dhclient –v as root fixed it for me.

I got this solution from this article:

3
  • 1
    Thanks, the only fix that worked in my case!
    – TerDale
    Aug 26, 2020 at 13:21
  • worked like a charm on CentOS 7.6 x64 vm. thanks a ton!
    – alphaGeek
    Sep 17, 2020 at 11:53
  • It worked like a charm, yet I have to write it each time I boot the machine. I followed all the steps in the article, still didn't work. So, this solution worked for me. Jul 17, 2021 at 0:50
9

When you make a new virtual machine (i.e. a guest OS) with VirtualBox it will, by default, make the NIC an Am79C973. Whilst this NIC may be supported by many OSes, this particular NIC does not seem to be supported by CentOS 7. This means that the only NIC which will show up inside your new CentOS 7 VM will be the loopback NIC. What you need to do is change the NIC to one which is supported like the 82543GC.

First, stop the CentOS VM if you haven't already, and then change the NIC using this command on your VirtualBox host:

vboxmanage modifyvm "testvm" --nictype1 82543GC

Now, start your CentOS VM again and you will notice that it has now has an NIC.

I hope that this helps.

3
  • I am not using vbox. I am just running centos as a dual-boot but I have the same.problem as op
    – samayo
    Dec 20, 2016 at 22:49
  • Was having the same problem as OP, this solved it for me.(VirtualBox+CentOS 7) Feb 7, 2017 at 18:34
  • This tip combined with the dhclient -v [unix.stackexchange.com/a/387060/426725] from @mike-hedman solved it for me
    – kopos
    Aug 30, 2020 at 3:05
8

In centos 7, the network interface name is enp0s3, to make the networking work, you need to edit the corresponding files by:

sudo vim /etc/sysconfig/network-scripts/ifcfg-emp0s3

And set the ONBOOT to yes

ONBOOT=yes
8
  • Woa woa woa, that is a gross oversimplification of CentOS 7 interface naming. See: cgit.freedesktop.org/systemd/systemd/tree/src/udev/… for reference. Chances are the interface is more likely a p#p### format interface, but either way it's better to determine the actual name than guess it.
    – Centimane
    Feb 16, 2017 at 13:27
  • Also, the asker is using CentOS 6.4, so CentOS 7 interface naming is not relevant. The interface naming changed drastically in 7.
    – Centimane
    Feb 16, 2017 at 13:40
  • 1
    Worked for me. Thanks. I am on free RHEL.To know the name of interface run pifconfig. Yes RHEL did not come with ifconfig. Even in sbin. Ubuntu is better in this regard.
    – NotAgain
    Feb 24, 2017 at 2:43
  • @Centimane Hey, thanks for letting me know that i oversimplify. But for me it is work, and not sure if it's a bad practice. Would you mind to share the proper way to get the correct interface for centos? So that it would be "Bulletproff" for future Centos Version. Feb 24, 2017 at 22:30
  • 1
    The interface names are based on the hardware, so the interface name is based off what type of NIC you're using, and how the hardware is reported to RHEL. Based off your interface name RHEL thinks your NIC is an embeded device, port 0 slot 3. But different hardware will use a different NIC name.
    – Centimane
    Feb 25, 2017 at 21:32
6

have a look at the NIC-configurationfiles /etc/sysconfig/networking/devices/ifcfg-ethX and check if the parameter ONBOOT exists. If not – add it.

grep "ONBOOT=yes" /etc/sysconfig/networking/devices/*
/etc/sysconfig/networking/devices/ifcfg-eth0:ONBOOT=yes
/etc/sysconfig/networking/devices/ifcfg-eth1:ONBOOT=yes

Reboot or /etc/init.d/network restart after the change should bring your interface up.

1
  • A hearty +1 for using grep to find out where they put the config this week! (BTW same issue on Centos6 and the fix still worked)
    – gbarry
    Sep 1, 2017 at 5:52
1

I think it's probably the network-setting that throws it. I've found mine work best with "Bridged Adapter", as you then use the host's network card directly. It'll also allow the virtual-computer to use DHCP to get it's own internal-IP from your router.

NAT is a bit strange, as you use only one IP-address (the same as the host's?) and instead relay on translation of ports - thus it's not really a separate IP for the virtual-computer. HostOnly I think only allows the virtual-computer to make "local network" with your host - ie. no external Internet. And that pretty much leaves you with just the loop-back device.

1
  1. sudo dhclient Done. No reboot required.

  2. If you want the dhcp client to start automatically at boot: sudo vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 change ONBOOT=no to ONBOOT=yes.

0

This looks to me like a /etc/udev/rules.d/70-persistent-net.rules issue. Unless this file is deleted, editing ifcfg-ethX won't help because whatever old settings you had will persist. Delete the file, then use "udevadm trigger" to recreate it.

1
  • I don't see how this relates to a device not being present.
    – thrig
    Mar 1, 2017 at 15:10
0

This applies specifically to VMBox where you installed a new clone (mine was CentOS) and don't see an IP address:

  1. Stop the VM. Go to Settings->Network->Advanced. Then reset MAC address by clicking on the blue icon on the right. Note the new MAC Address somewhere.
  2. Start the VM. Go to System->Preferences->Network Connections. Edit the Connection eth0 ->Device MAC address with new MAC address from step#1 adding ":" between two characters. e.g. 08012741798D to 08:01:27:41:79:8D and save
  3. Reboot, then logged in as root: cd /var/lib/NetworkManager
  4. remove or move NetworkManager.state to another folder e.g.: mv NetworkManager.state NetworkManager.state.save
  5. run: service NetworkManager stop
  6. run: service NetworkManager start
  7. To see new IP address run: ifconfig -a
0

The best solution worked for me is the following:

  1. Configure the DHCP client on the default network interface eth0 by executing the following command:
dhclient eth0
  1. Edit the main network configuration file to make sure networking is enabled using the command:
vi /etc/sysconfig/network

and make sure that it has networking set to yes

NETWORKING=yes
  1. Edit the network configuration file for eth0 to enable it to use a dynamic ip using dhcp
vi /etc/sysconfig/network-scripts/ifcfg-eth0

Modify the file to have the following:

DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"
NM_CONTROLLED="no"

For me it worked without the double quotes ""

  1. Save the file and then restart the network service using the following command:
service network restart

Make sure that eh0 has pulled an IP using the following command:

ifconfig

Solution from : https://www.jesox.com/blog/how-configure-internet-access-centos-minimal-install

-1

I ran into the same problem; I solved it configuring the network in the virtualBox configuration → network setting page: I selected "Bridged Networking".

http://www.thegeekstuff.com/2012/03/virtualbox-guest-additions/

You must log in to answer this question.

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