IP address problem after restarting CentOS 7 system

When configuring Zookeeper, I restarted CentOS 7, and found that using XShell to remotely connect to the system (host: 192.168.186.128) timed out.

I have long been accustomed to various bugs and accidents in the operating system and when writing code; because I know that they can all be resolved within a limited time.

Then, I went directly to the system page, opened the command line and typed ifconfig:

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
  inet 192.168.186.130  netmask 255.255.255.0  broadcast 192.168.186.255
  inet6 fe80::20c:29ff:fe1a:6c13  prefixlen 64  scopeid 0x20<link>
  ether 00:0c:29:1a:6c:13  txqueuelen 1000(Ethernet)
  RX packets 636  bytes 48167(47.0 KiB)
  RX errors 0  dropped 0  overruns 0  frame 0
  TX packets 237  bytes 26851(26.2 KiB)
  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
  inet 127.0.0.1  netmask 255.0.0.0
  inet6 ::1  prefixlen 128  scopeid 0x10<host>
  loop  txqueuelen 0(Local Loopback)
  RX packets 0  bytes 0(0.0 B)
  RX errors 0  dropped 0  overruns 0  frame 0
  TX packets 0  bytes 0(0.0 B)
  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

According to the previous system snapshot backup, the previous information can be obtained as:

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
  inet 192.168.186.128  netmask 255.255.255.0  broadcast 192.168.186.255
  inet6 fe80::20c:29ff:fed8:e9b9  prefixlen 64  scopeid 0x20<link>
  ether 00:0c:29:d8:e9:b9  txqueuelen 1000(Ethernet)
  RX packets 1370575  bytes 1933632481(1.8 GiB)
  RX errors 0  dropped 0  overruns 0  frame 0
  TX packets 360561  bytes 85054851(81.1 MiB)
  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
  inet 127.0.0.1  netmask 255.0.0.0
  inet6 ::1  prefixlen 128  scopeid 0x10<host>
  loop  txqueuelen 0(Local Loopback)
  RX packets 19044  bytes 38146469(36.3 MiB)
  RX errors 0  dropped 0  overruns 0  frame 0
  TX packets 19044  bytes 38146469(36.3 MiB)
  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

It can be seen that after the restart, the host address has changed from 192.168.186.128 to 192.168.186.130, and the original eno16777736 has also become ens33.

Then, I tried to execute the command service network restart or systemctl restart network to restart the network, and found an error:

Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe"for details.

In order to view detailed error information, execute the command cat /var/log/messages | grep network, and find the error:

...
Sep 2510:55:30 localhost network:[FAILED]
Sep 2510:55:30 localhost NetworkManager[16202]:<info>  renaming /etc/sysconfig/network-scripts/ifcfg-eno16777736 ->/etc/sysconfig/network-scripts/ifcfg-ens33
Sep 2510:55:30 localhost network: Bringing up interfaceens33:  Error: no device found for connection 'eno16777736'....

The error message is that the network card eno16777736 failed to load.

So execute the command cd /etc/sysconfig/network-scripts/ to enter the folder where the network configuration is stored.

Looking at the files in the directory, it is found that only the configuration file ifcfg-eno16777736 corresponding to the original network card eno16777736 exists, but there is no configuration file corresponding to the network card ens33. So it is inferred that after restarting, the system deleted the original network card, and then enabled the new network card with a new IP address. To this end, the solution is to replace the network card configuration file and reconfigure the IP address to the old IP address, and restart the network.

First execute the command cp ifcfg-eno16777736 ifcfg-ens33 to copy the files.

Then, execute the command to edit the file vim ifcfg-ens33; change the network card name from the original eno16777736 to ens33, and ensure that the IP address is the original address:

IPADDR=192.168.186.128
NAME=ens33
DEVICE=ens33

At the same time, execute the command to delete the configuration file rm ifcfg-eno16777736 of the invalid network card.

Then execute the command systemctl restart network to restart the network, and then execute ifconfig, you can find that the IP address has been successfully replaced with the original IP address:

[ root@localhost network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
  inet 192.168.186.128  netmask 255.255.255.0  broadcast 192.168.186.255
  inet6 fe80::20c:29ff:fe1a:6c13  prefixlen 64  scopeid 0x20<link>
  ether 00:0c:29:1a:6c:13  txqueuelen 1000(Ethernet)
  RX packets 777  bytes 57063(55.7 KiB)
  RX errors 0  dropped 0  overruns 0  frame 0
  TX packets 280  bytes 31690(30.9 KiB)
  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
  inet 127.0.0.1  netmask 255.0.0.0
  inet6 ::1  prefixlen 128  scopeid 0x10<host>
  loop  txqueuelen 0(Local Loopback)
  RX packets 4  bytes 352(352.0 B)
  RX errors 0  dropped 0  overruns 0  frame 0
  TX packets 4  bytes 352(352.0 B)
  TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

If no error is reported after the restart but the IP address has not changed, perform another restart to prevent caching problems.

Re-use XShell to connect to the system. If the connection timed out the first time, turn it off and try again to prevent caching problems.

Finally, restart the system and find that the IP address and network card are normal and unchanged. You can use XShell to remotely access the CentOS 7 system normally.

Recommended Posts

IP address problem after restarting CentOS 7 system
Centos7 configure IP address
Centos: add an IP address
Centos7 configuration host name and IP address
centos system management
CentOS system startup process
VirtualBox install CentOS system
Ubuntu18.04, Centos7 static IP
centos7 install keepalived problem
Centos7.2 system optimization original
Centos system process management