Changing Static IP Address on CentOS 7
1. Identify the Network Interface
2. Edit the Network Configuration File
3. Update the Configuration File
4. Restart the Network Service
5. Verify the Configuration
Conclusion
Changing the network configuration and assigning a static IP address to a server or computer running CentOS 7 is an essential task for network management. Below is a step-by-step guide on how to accompli this.
1. Identify the Network Interface
First, you need to identify which network interface you want to assign the static IP address to. Use the following command to list all network interfaces:
ip addr show
This command will display all network interfaces along with their current IP addresses. You might see names like eth0
or ens33
.
2. Edit the Network Configuration File
Once you've identified your network interface, you need to edit the corresponding configuration file. This file is typically located at /etc/sysconfig/network-scripts/ifcfg-<interface_name>
. For example, for the eth0
interface, the file path would be:
/etc/sysconfig/network-scripts/ifcfg-eth0
Open this file with a text editor, such as vi
or nano
:
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
3. Update the Configuration File
After opening the file, add or update the lines specifying the static IP address, netmask, gateway, and DNS servers. For example, you can use the following configuration:
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
The meanings of these settings are:
TYPE
: The interface type (usually Ethernet).BOOTPROTO
: The protocol for assigning IP addresses (usenone
for static IP).NAME
: The interface name.DEVICE
: The device name.ONBOOT
: Whether the interface ould be activated at boot (yes
).IPADDR
: The static IP address.PREFIX
: The subnet mask (e.g.,24
=255.255.255.0
).GATEWAY
: The default gateway.DNS1
andDNS2
: The DNS servers.
4. Restart the Network Service
After saving and closing the configuration file, you need to restart the network service to apply the changes. Use the following command:
sudo systemctl restart network
This command will restart the network service, and the new configuration settings will take effect.
5. Verify the Configuration
Finally, verify that the changes have been applied correctly by checking the IP address of the interface:
ip addr show eth0
Additionally, you can test the network connection by pinging an external IP address:
ping google.com
Conclusion
By following these steps, you can assign a static IP address to a network interface on a CentOS 7 system. Assigning a static IP address is crucial for stabilizing the server's position on the network and improving management for certain services (e.g., web servers, database servers).
Eka Sunucu Bilişim Hizmetleri, BTK lisansı ile ticari amaçla faaliyet gösteren yasal yer sağlayıcıdır.