How to Set Manual IP Address in CentOS Linux
IP addresses play an essential role in networking, allowing devices to communicate with each other. In some cases, you might need to set a manual IP address for your CentOS Linux machine instead of relying on DHCP. Here's a step-by-step guide on how to do it.
Prerequisites
Before we start, make sure the following conditions are met:
- You have root access or know the sudo password.
- Networking is enabled and started on your CentOS Linux machine.
Steps to Set Manual IP Address in CentOS Linux
1. Open the Network Interface Configuration File
First, open the network interface configuration file for the network interface you want to set a static IP address for using your favorite text editor:
sudo nano /etc/sysconfig/network-scripts/ifcfg-<interface_name>
Replace <interface_name>
with the name of the network interface, such as eth0 or wlan0.
2. Edit the Configuration File
Now, modify the configuration file by adding or updating the following lines:
TYPE=Ethernet
BOOTPROTO=static
DEFROUTED_KEEP_OPEN=yes
IPADDR=<your_ip_address>
NETMASK=<subnet_mask>
GATEWAY=<default_gateway>
ONBOOT=yes
Replace <your_ip_address>
with the IP address you want to set, <subnet_mask>
with the subnet mask for your network, and <default_gateway>
with the default gateway.
3. Save and Exit the File
After modifying the configuration file, save and exit it using the respective command based on your text editor:
Ctrl+X -> Y -> Enter (nano)
4. Restart the Networking Service
Restart the networking service for the changes to take effect:
sudo systemctl restart network
Alternatively, you can use:
sudo service network restart
5. Verify the New IP Address
To verify that your CentOS Linux machine has the new IP address, open a terminal and run:
ip addr show <interface_name>
Replace <interface_name>
with the name of the network interface. Look for the line showing the new IP address.
Conclusion
Setting a manual IP address in CentOS Linux is an essential skill when working with networking configurations. In this post, we covered how to set a static IP address using a simple and effective step-by-step guide. If you found this tutorial helpful, please leave a comment below. Happy coding!