Solve the problem of VMware virtual machine Centos7 switching network and changing IP

Solve the problem of VMware virtual machine Centos7 switching network and changing IP

Problem Description

Learning docker, using docker to deploy mysql, redis, nacos in the VMware virtual machine Centos7 system, the ip assigned by the virtual machine DHCP is 192.168.171.128, using the connection tool xshell to connect is no problem. The next day, the company lost its network and switched to a WIFI network, and all client tools could not connect.

Reason: Due to the network switching WIFI, the IP reassigned by DHCP of the virtual machine is 192.168.171.129.
Thinking: Is it possible to set a fixed static IP? Even if the network changes the IP will not change

Centos7 set fixed static IP

1. VMware menu Edit->Virtual Network Editor. Record the gateway and subnet mask
insert image description here
insert image description here
3. ip addr: View the ip address and network card, my network card is ens32, maybe others are different, you need to check it yourself
insert image description here
4. Edit the configuration file corresponding to ens32, located in/etc/sysconfig/network-scripts/ifcfg-你的网卡名字

cd /etc/sysconfig/network-scripts/

insert image description here
4. Modify ifcfg-ens32 network card configuration file

vim ifcfg-ens32

After entering, click i to start editing and modifying

BOOTPROTO="static"	
ONBOOT="yes"

insert image description here
Add at the bottom

IPADDR="192.168.171.128"
GATEWAY="192.168.171.2"
NETMASK="255.255.255.0"
DNS1="192.168.171.2"

Note: IPADDR is the static IP address set. GATEWAY is the gateway, DNS1 is consistent with the gateway, and the two are consistent with the gateway recorded in step 1 above. Here I am 192.168.171.2. NETMASK is the subnet mask.

After editing, click on the keyboard Esc, enter :wq, save and exit.

5. Restart the server:service network restart

Guess you like

Origin blog.csdn.net/qq_45297578/article/details/130720342