Modify the dynamic IP address of the Linux virtual machine to a static IP address in VMware

Why do you need to change the virtual machine to a static IP address?

Because if you want to remotely connect to your virtual machine, or the database and projects on the virtual machine, but your virtual machine has a dynamic IP address, the IP address of the virtual machine will change every time you restart the virtual machine, which leads to It is a waste of time to re-query the IP address of the virtual machine every time the virtual machine is restarted, and then reconnect. Therefore, the following describes how to modify the dynamic IP address of the Linux (CentOS) virtual machine to a static IP address.

1. Open the VMware virtual network editor

2. Click Change Settings in the lower right corner

3. Select VMnet8 NAT mode, modify the third part of the subnet IP below (any number is fine, the range is 0-255), open the NAT settings after editing

4. Change the first three parts of the gateway IP to the same number as the subnet IP you set, and set the fourth part of the gateway IP to 2. After the setting is complete, click OK

5. Click OK

Please ensure that the network connection mode of the virtual machine is NAT mode

6. Open the command line interface of the Linux virtual machine, and then execute the command su to switch the administrator account (the password will not be displayed when entering the password, but it has actually been entered)

*Note: Mine is CentOS 7, so my Linux command line window may not be the same as yours

su

7. Enter the command vi /etc/sysconfig/network-scripts/ifcfg-ens33 to switch to the configuration file

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

8. After switching to the configuration file, press the INSERT key on the keyboard to modify the configuration. After the modification is completed, press the ESC key on the keyboard to exit the modified configuration

BOOTPROTO=dhcp changed to BOOTPROTO=static

Change ONBOOT=no to ONBOOT=yes

And add IPADDR , NETMASK , GATEWAY these three configuration parameters (capital letters)

BOOTPROTO=static
ONBOOT=yes

IPADDR=192.168.xxx.xxx #前三部分设置为第3步中设置的子网IP,第四部分0-255任意一个数,设置好后这个就是虚拟机的静态IP地址
NETMASK=255.255.255.0
GATEWAY=192.168.xxx.2 #设置为第4步中设置的网关IP

 9. Enter : wq! and press Enter to save the modification

:wq!

10. Enter the command reboot to restart the virtual machine, or restart it directly through the VMware operation interface

reboot

So far, the dynamic IP address has been successfully changed to a static IP address.

Guess you like

Origin blog.csdn.net/Coin_Collecter/article/details/130035715