Search The Site

How To Configure A Static IP In CentOS Redhat and Fedora

A static IP address is mainly used for name resolution, so that a computer can be reached over the network by its host / domain name. Web and FTP servers in particular benefit from static addressing also known as fixed or hard coded addressing. Using static IP addresses on home networks allows us protection against network security problems. Using static IP address assignment for all devices on the home network guarantees to avoid potential address conflicts where DHCP may supply an address already assigned statically elsewhere on the network.

The following is for most Linux systems, however if you are using Debian or Ubuntu the procedure is different, please use my article titled setup and configure a static IP on Debian if you are running a Debian box.

To configure a static IP on CentOS - Redhat or Fedora, complete the following steps.

  • Login into your system as a superuser from a terminal as follows;
  • su -
  • Then change directories to cd /etc/sysconfig/networking/devices
  • Next, we want to edit the ifcfg-eth0 file, with your favorite editor type the following in a terminal nano ifcfg-eth0
  • With the ifcfg-eth0 file open in your editor enter the following values;
  • DEVICE=eth0
  • BOOTPROTO=none
  • HWADDR=00:0F:58:GF:89:4E (this is the MAC Address of your eth0 nic adapter)
  • ONBOOT=yes
  • TYPE=Ethernet
  • USERCTL=no
  • IPV6INIT=no
  • PEERDNS=yes
  • NETMASK=255.255.255.0
  • IPADDR=192.168.4.5
  • GATEWAY=192.168.4.1

Next, we need to restart the network with the following command from a terminal service network restart Make sure you are still logged in as a superuser.

Next, change directory to /etc and edit the resolv.conf file with nameserver information as follows;

  • cd /etc
  • nano resolv.conf
  • search your-dns-search-path
  • nameserver 192.168.4.5 (your first nameserver)
  • nameserver 192.168.4.6 (your second nameserver, if you have one)

Next, we need to apply the changes, we can do this as follows;

  • From a terminal logged in as a superuser type ifdown eth0 and then type ifup eth0

That's it, you are done. Test your internet by launching a browser or ping your favorite host.