53

I am already a little bit familiar with Linux distros like Debian or Ubuntu (yeah, very similar) but I wanted to try Red Hat based - CentOS 6.2. I have installed it on my Windows 7 host in VirtualBox and tried to play with it a little.

I have come across a small problem, namely: the default eth0 interface is down by default. I use the option with NAT (the virtual machine is 'behind' the host). Even if I bring the interface up with ifconfig eth0 up, it does not work right away. I get this after bringing the interface up:

eth0      Link encap:Ethernet  HWaddr 08:00:27:0F:00:8A
          inet6 addr: fe80::a00:27ff:fe0f:8a/64 Scope:Link
          UP BROADCAST RUNNNING MULTICAST MTU:1500 Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carriers:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:468 (468.0 b)
          Interrupt:19 Base address:0xd020

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

virbr0    Link encap:Ethernet  HWaddr 52:54:00:75:C2:9B
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
[root@centos ~]# _

What should be done more to configure the network on CentOS machine?

3
  • 2
    There is no eth1 on your screenshot... Btw, try to run DHCP on your interface: dhclient eth0.
    – pbm
    Apr 17, 2012 at 18:58
  • 1
    @pbm 1) I changed eth1 to eth0 in the description. 2) dhclient eth0 worked :) thanks. How can I make it default - run like this after reboot ?
    – Patryk
    Apr 17, 2012 at 19:18
  • I'm not sure, but check out this blog post: blog.malaya-digital.org/…
    – pbm
    Apr 17, 2012 at 19:49

4 Answers 4

61

Edit /etc/sysconfig/network-scripts/ifcfg-$IFNAME. Change the ONBOOT line's value to yes.

$IFNAME will be eth0 on many EL6 boxes, but on boxes using the Consistent Network Device Naming scheme, it might be something else, like en3p1. This scheme is optional in EL6 but the default in EL7 and newer. Use the command ip link to get a list of network interfaces, including the ones that are currently down.

In your future installs, pay more attention. You blew past an option in the network configuration section that let you tell it to bring the interface up on boot. This on-boot option is off by default in EL6 and later, whereas in previous versions, it was on by default.

To make the network interface come up on first boot at install time, go to the ConfigureGeneral tab in the network configuration screen, then check the box labeled Automatically connect to the network when available.

As to why they changed this, I'd guess security reasons. It gives you a chance to tighten things down a bit from the default setup before bringing up the network interface for the first time, exposing the box to the outside world.

2
  • Precisely the info I was looking for. Thank you! Mar 22, 2019 at 16:57
  • One small additional step, running service network restart after changing the ONBOOT to yes will bring up the interface.
    – sarangj
    Dec 17, 2021 at 22:52
8

If you don't have a DHCP server in your network, you must set a static IP address. Please consider the following example:

vim /etc/sysconfig/network-scripts/ifcfg-eth0

BOOTPROTO=none
DEVICE=eth0
IPADDR=192.168.1.10 # your IP address
NETMASK=255.255.255.0 # your netmask
NETWORK=192.168.1.0 
ONBOOT=yes

Add GATEWAY to your /etc/sysconfig/network file:

NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=hostname.domainname
GATEWAY=192.168.1.1 # your gateway

Issue the following command to start network on boot:

chkconfig network on

Restart your network service:

service network restart

Take a look at your network interfaces

ifconfig
5

You didn't mention what version of CentOS you are using. If I'm not mistaken, 6.x uses NetworkManager by default.

I rarely install X windows on my servers, so NetworkManager is just a pain for me. I disable it and enable the standard 'network' service.

chkconfig NetworkManager off
chkconfig network on

service NetworkManager stop
service network start

To enable DHCP on the interface, run system-config-network, edit the appropriate device, save, and restart the network service. Alternately, you can edit /etc/sysconfig/network-scripts/ifcfg-eth0 and add

ONBOOT=yes
BOOTPROTO=dhcp

Save changes and restart the network service.

1

From what I have gathered from experimenting and reading, I agree with uther that Network Manager seems to load by default, but the network service does not.

When I recently had a VM host starting up without eth0 showing up in ifconfig output, it was because I had Network Manager running, network not running, and NM_CONTROLLED=no in my /etc/sysconfig/network-scripts/ifcfg-eth0 file.

As soon as I ran service network restart, eth0 showed up in ifconfig output. Rebooting, however, caused it to go away again.

The solution for me appears to be setting NM_CONTROLLED=no in /etc/sysconfig/network-scripts/ifcfg-eth0, then turning on the network service on startup (chkconfig network on, as uther and alexnorthsoul point out). I could (should?) probably turn NetworkManager off by default, but it is working for me now and I am nervous about touching anything else.

By the way, my goal was to get the system to honor the my selected static IP. When I left NetworkManager running and set NM_CONTROLLED=yes (or omitted it), I got eth0 showing up in ifconfig, but the address was a DHCP address, not my static IP. So turning off NetworkManager spared me from DHCP, and turning on network caused it to load my settings that included the static IP.

I am no sys admin, but rather a developer, so these are not words from a CentOS expert, but just a survivor of configuring the VMs I needed.

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.