How To Configure Static IP Address On CentOS

by lifeLinux on September 16, 2011

Configure a static IP address on CentOS is quite easy. In this article, I’ll show you how to do it through command line.

Log on as root, change directory to /etc/sysconfig/network-scripts and list all available devices with the following command

# cd /etc/sysconfig/network-scripts
# ls -la | grep ifcfg-

Sample outputs

-rw-r--r--  3 root root   244 Oct 15  2010 ifcfg-eth0
-rw-r--r--  3 root root   141 Oct 15  2010 ifcfg-eth1
-rw-r--r--  1 root root   254 Oct 13  2010 ifcfg-lo

Find the configuration file corresponding to the NIC for which you want to set a static IP and edit it. In this example I’ll configure a static IP address for eth1 and use the following Internet Protocol Version 4:
# IP address: 192.168.1.10
# Netmask: 255.255.255.0
# Gateway IP: 192.168.1.1
# DNS Server IP # 2: 8.8.8.8
# DNS Server IP # 2: 8.8.4.4

# vi ifcfg-eth1

Sample outputs

# Intel Corporation 82574L Gigabit Network Connection
DEVICE=eth1
HWADDR=00:25:90:0B:A3:E5
ONBOOT=no
HOTPLUG=no
BOOTPROTO=dhcp
TYPE=Ethernet

Now set the parameters below according to your settings, sample static ip configuration

# Intel Corporation 82574L Gigabit Network Connection
DEVICE=eth1
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:25:90:0B:A3:E5
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ONBOOT=yes

To setup DNS servers, edit /etc/resolv.conf, enter

# vi /etc/resolv.conf

Sample configurations

nameserver 8.8.8.8
nameserver 8.8.4.4

Now save the configuration file and exit the text editor. To apply changes, we need to bring the network interface down and back up, type the following command

# /etc/init.d/network restart

Or,

# service network restart

Related Posts:

Previous post:

Next post: