How to add a static IP in CentOS

To start you need to log into your server with root privileges

To configure the main IP address as static, you must change the entry for eth0 in /etc/sysconfig/network-scripts/ifcfg- eth0. To carry out this change, enter the following:

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

You will be displayed with the below file:

DEVICE=eth0
BOOTPROTO=dhcp
BROADCAST=ABC.DEF.GHI.JKL
IPADDR= ABC.DEF.GHI.JKL
NETMASK=255.255.255.255
NETWORK= ABC.DEF.GHI.0
ONBOOT=no
NM_CONTROLLED=no

Now change the BOOTPROTO to STATIC

ONBOOT to YES

Fill in your network details IPADDR etc

You can also set your DNS servers on this file. You can do this by adding a line ‘DNS1=8.8.8.8’

Now exit the file:

:qw

Restart your network services

Service network restart