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
DEVICE=”eth0”
HWADDR=MAC Address*System MAC*
NM_CONTROLLED=”no”
ONBOOT=”yes”
BOOTPROTO=”dhcp”
Restart the network service.
/etc/init.d/network restart
or
service network restart
DEVICE=”eth0”
HWADDR=MAC Address*System MAC*
NM_CONTROLLED=”no”
ONBOOT=”yes”
BOOTPROTO=”static”
IPADDR=192.168.x.x.
NETMASK=255.255.255.0.
*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
*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.