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.