How to set a static ip address on CentOS, Fedora, or Red Hat Linux

Open up the following file with your favorite text editor. Change eth0 to the interface you need, like “wlan0” or “eth1”.

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

The file should look something like the following.

DEVICE=eth0
HWADDR=0A:2G:F3:56:66:4B
TYPE=Ethernet
UUID=aeh9421c-6a62-712c-886d-347813g8d1dh
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp

To set the static IP address change “BOOTPROTO=dhcp” to “BOOTPROTO=static” and add the following to the end of the file. If you want/need the interface to come up when the computer boots up then be sure to change “ONBOOT=no” to “ONBOOT=yes”.

BROADCAST=192.168.1.255
DNS1=8.8.8.8
GATEWAY=192.168.1.1
IPADDR=192.168.1.110
NETMASK=255.255.255.0

Also, on some newer versions of CentOS you may need to add NM_DISABLED=no

So your file should now look like this.

DEVICE=eth0
HWADDR=0A:2G:F3:56:66:4B
TYPE=Ethernet
UUID=aeh9421c-6a62-712c-886d-347813g8d1dh
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
BROADCAST=192.168.1.255
DNS1=8.8.8.8
GATEWAY=192.168.1.1
IPADDR=192.168.1.110
NETMASK=255.255.255.0

Save the file and restart networking.

service network restart

Finally, check you IP address with ifconfig.

root@localhost ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 0A:2G:F3:56:66:4B  
          inet addr:192.168.1.110  Bcast:192.168.1.255  Mask:255.255.255.0

Leave a Reply

Your email address will not be published. Required fields are marked *