Q: I have come across a few how-to article on setting a static IP address but I always seem to get stuck. Can you tell me simply how to configure CentOS or Red Hat for a static IP address. I am currently using CentOS 5.
A: This is a simple task once you understand the files and changes involved. Let's take a look at how this is done.
You will need the following information in order to complete this configuration:
- IP Address
- Gateway Address
- Broadcast Address
- Network Address
- DNS Server Addresses
- System Hostname
Disable Network Manager
The first thing I like to do is to turn off NetworkManager. This service is responsible for requesting DHCP addresses and configuring the network interfaces. Since we are setting them statically we do not need it.
service NetworkManager stop
systemctl stop NetworkManager
Enable network Service at Boot
Ensure the network service is set to start at boot.
chkconfig network on
systemctl enable network
Edit Configuration Files
Now that NM (NetworkManager) is out of the way we need to edit three files.
NOTE: The name of your network interface may differ from eth0. If so, replace eth0 with the name of your device in the command above.
First let’s edit /etc/sysconfig/network. Here w e will need to tell the system to turn on networking, the hostname of the machine and the gateway. Open the file in your favorite text editor and add or change the following lines. Of course you will need to make sure the configuration matches your system, this is just an example.
Save and close the file.
Let’s move on to editing the /etc/sysconfig/network-scripts/ifcfg-eth0 file. Open the file in your favorite text editor and add or change the following lines.
NOTE: Remember to place the name of your interface and your information in this file. The above is just an example.
Now that the network interface is taken care of we need the final important piece of the puzzle, DNS. Without DNS you will not be able to go to a website by name, on connect to anything else on the network unless you know the IP address. To tell the system what DNS servers to use we edit the /etc/resolv.conf file. Open the file in your favorite editor and add or change the following lines (search line is optional).
Restarting the network Service
Now that we have given the system the necessary information all we need to do is restart the network service.
service network restart
systemctl restart network
For more information about restarting services with systemctl see "Restarting Services in Red Hat 7 or CentOS 7 using systemctl".
That’s it. I hope this answers your question and helps you easily configure your system for a static IP address. If you have any additional questions feel free to post them in the comments.
This site uses Akismet to reduce spam. Learn how your comment data is processed.