Main Content

CentOS 6 Has No Network Connectivity ?

This is for those of you who are new to CentOS.

By default CentOS 6 will not configure network interfaces on a new installation which means the host will have no network connectivity, we can correct this inconvenience with little effort. Of course this means the user(you) is left with the decision to configure the network interface(s) with either a static or dynamically assigned IP addresses.

First of all we need to see the contents of the ifcfg-eth0 file.

cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=”eth0”
HWADDR=”MAC Address”
NM_CONTROLLED=”yes”
ONBOOT=”no”

The output above indicates eth0 is disabled, this is when you either opt to set a static IP or dynamically assigned IP.

With the text editor of your choice open the /etc/sysconfig/network-scripts/ifcfg-eth0 and edit as indicated below.

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

DHCP Configuration

DEVICE="eth0"
HWADDR=MAC Address*System MAC*
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="dhcp"
  • DEVICE=”eth0″ – Name of Network Interface.
  • HWADDR=MAC Address*System MAC* – MAC address of Network Interface.
  • NM_CONTROLLED=”no” – Network Manager should disable since it’s unnecessary in this configuration.
  • ONBOOT=”yes” – – Means the NIC will be started during boot.
  • BOOTPROTO=”dhcp” – Instructions the OS to find a DHCP server from which to obtain an IP address. The DHCP server will assign all necessary network information including IP address, Netmask, Gateway and DNS server.

Restart the network service.

/etc/init.d/network restart

or

service network restart

Static Configuration

DEVICE="eth0"
HWADDR=MAC Address*System MAC*
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR=192.168.x.x.
NETMASK=255.255.255.0.
  • DEVICE=”eth0″ – Name of Network Interface.
  • HWADDR=MAC Address*System MAC* – MAC address of Network Interface.
  • NM_CONTROLLED=”no” – Network Manager shoudl be disable since it’s unnecessary in this configuration.
  • ONBOOT=”yes” – Means the NIC will be started during boot.
  • BOOTPROTO=”static” – IP configuration will be static.
  • IPADDR=192.168.x.x – System IP address.
  • NETMASK=255.255.255.0 – Network Mask.

Gateway Configuration

*DHCP Users should ignore this step.

In order to add a Gateway to our system we need to edit /etc/sysconfig/network.

In order to add the network gateway edit /etc/sysconfig/network and add GATEWAY=192.168.x.x.

NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.111.1

DNS Configuration

*DHCP Users should ignore this step.

Now we add the DNS server(s) for our host. Edit /etc/resolv.conf and add nameserver 192.168.x.x.

nameserver 192.168.111.1

Restart the network service. This will make sure the changes take effect.

/etc/init.d/network restart

or

service network restart

As stated by

  • Cam
  • it is a good idea to have console access to the server in case you lock your self out it.

    Comments

    1. Commented on
      Comment by Cam

      Thanks! This helped me out a ton! I will add that I did have the file /etc/sysconfig/network-scripts/ifcfg-eth0 for my eth0 interface. Creating my own seemed to work. I was doing all this from a remote location so I would add that being at the console is imperative because you will lose network connectivity.

      1. Commented on
        Comment by PIkachu

        So, anyone else believes that CentOS removing network setup from installation is most bizarre and stupid thing in the world?? Am I alone with this?

        1. Commented on
          Comment by luisventura

          No, you are not alone. I find it to be an unnecessary pain.

        2. Commented on
          Comment by Dave McLure

          It’s not just Centos – I went through a very similar set of monkey business getting a newish version (17 I think?) of Fedora to work recently. That was one of the reasons I abandoned Fedora in fact. It almost seems like some kind of conspiracy. Requiring NetworkManager? Requiring a GUI application to manage a server? What kind of lunacy is this? Requiring a GUI eliminates one of the biggest server performance advantages Linux/Unix has over other OS’s!

        3. Commented on
          Comment by darkelf

          its just a pain in the ass. You are not alone bro.

    2. Commented on
      Comment by Cam

      Correction:

      *didn’t have the file /etc/sysconfig/network-scripts/ifcfg-eth0*

    3. Commented on
      Comment by Gerald Wiltse

      +2 for Nice looking code blocks
      -1 for critical typo on a tutorial (please correct)

      Wish I could just choose customize now and choose “network tools” during install.

      You probably want to correct the fourth line below.

      DEVICE=”eth0”
      HWADDR=”MAC Address”
      NM_CONTROLLED=”yes”
      ONBOT=”no”

      1. Commented on
        Comment by luisventura

        Thank you for pointing out the error.

    4. Commented on
      Comment by Thomas

      your a star….

    5. Commented on
      Comment by tayab

      dear plz try

      ifconfig eth0 up

      dhclint

      then try
      best of luck

      1. Commented on
        Comment by tayab

        sorry it’s
        dhclient

    6. Commented on

      […] I found this article which walks you through changing the file at /etc/sysconfig/network-scripts/ifcfg-eth0 from […]

    Comments are closed.