Linux virtual IP always changes? How to fix IP?

Foreword:

Virtual machine: VMware16

System: centOS7

1. Problem

        Every time I open VMware on my computer and enter Linux, I find that sometimes the IP will change, causing problems in transferring files or remote connections. It is relatively troublesome to change other files every time I change the IP.

2. Reasons

Because the ip of the virtual machine is dynamically allocated , it is possibleThere are several reasons leading to its change:

  1. The network the host is connected to is different. For example, last time it was connected to the hotspot of your mobile phone, this time it is connected to a network cable;
  2. Shut down the host and restart it;
  3. Uninstall VMware and re-import the virtual machine.

3. Solution (fixed IP address)

(1) Preparation work

1. Query the virtual machine IP address

# ifconfig

2. Query the gateway ip

Edit One>Virtual Network Compiler One>Change Settings One>Select at the topNAT mode, select at the bottom NAT settingsone>Gateway IP

(2) Fixed IP

  • Location 1>Computer

  • Enter the following location

etc/sysconfig/network-scripts

  • Right-click to enter the terminal and open the virtual machine network card configuration file ifcfg-ens33

# vim ifcfg-ens33

  • Changedhcp to static and let the IP be assigned The rules are static and never change

BOOTPROTO="static"

  •  Configure the virtual machine IP address, gateway IP, and domain name resolution server at the end of the network card configuration file.

IPADDR="own IP address"
GATEWAY="own gateway IP"

NAS1="Same as gateway IP"

 

  • Exit editing and save and exit 

Esc one>:wq 

  • Restart the network card

#  systemctl restart network

 

(3) Check whether the network is connected

1. View on this machine

> ping the IP of the virtual machine

 

2.Virtual machine viewing

#ping local IP

 

(4) Selection of local IP

 1. Cable network card

2. Wireless network card

 

3. Not using VMware Network

Guess you like

Origin blog.csdn.net/m0_61059796/article/details/134407314