How to change centos dynamic intranet IP to static one

To change CentOS from a dynamic intranet IP to a static IP, you need to follow the following steps:

  1. Open a terminal and log in as root.

  2. Edit network configuration files. Enter the following command in the terminal:

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

This command will open the eth0 configuration file. If your network interface name is not eth0, replace it with the correct interface name.

3. In the opened configuration file, find the following line:

BOOTPROTO=dhcp

Modify it to:
BOOTPROTO=static

This will tell the system to use a static IP address.

4. In the same configuration file, find the following line:

IPADDR=

Enter the static IP address you want assigned to CentOS in this line. For example:

IPADDR=192.168.1.100

5. In the same configuration file, find the following line: 

NETMASK=

Enter the subnet mask in this line. For example:
NETMASK=255.255.255.0

6. In the same configuration file, find the following line: 

GATEWAY=


Enter the gateway address in this line. For example:

GATEWAY=192.168.1.1

7. Save and close the configuration file. 

Restart the network service for the changes to take effect. Enter the following command in the terminal:

systemctl restart network

8. Check whether the new static IP address has been assigned. Enter the following command in the terminal: 

ip addr show eth0


This command will display the IP address, subnet mask, and gateway of the eth0 interface. If the IP address displayed is the same as the one you specified in step 4, then you have successfully changed CentOS from a dynamic intranet IP to a static IP.

Note: Before changing the network configuration, make sure you have obtained the correct IP address, subnet mask, and gateway and entered them correctly into the configuration file.

Guess you like

Origin blog.csdn.net/qq_54276699/article/details/132021015