[VMware virtual machine] Linux set a fixed IP

1 Set the network connection method of the virtual machine

Right-click the virtual machine name and select "Settings", adjust the network adapter to the following configuration, and click "OK" to save
Network connection

2 Configure the address parameters of NAT mode

Edit—virtual network adapter—change settings
Address parameter
Select VMnet8—uncheck "Use local DHCP service to assign IP addresses to virtual machines"—fill in the subnet IP (custom)—click NAT settings to
Address parameter
modify the gateway IP (here set to 192.168.2.1 )
Gateway IP

3 Configure host VMnet8 address parameters

Open the settings, find "Network and Internet", click "Change adapter options" to
Adapter options
find VMnet8, right-click the properties, select the properties of IPV4, and change the IP address as follows
Modify IP address

4 Modify the configuration file of the virtual machine system to a fixed IP

Enter the virtual machine, use the following command to modify the configuration file

cd /etc/sysconfig/network-scripts/
ls
sudo vim ./ifcfg-ens33

Modify the configuration file
Modify the configuration as follows:
(1) BOOTPROTO is set to "static"
(2) Annotate all IPV6 protocols
(3) ONBOOT is set to "yes"
(4) Add the following configuration:

DNS1=114.114.114.114
IPADDR=192.168.2.2 #自定义固定IP
NETMASK=255.255.255.0
GATEWAY=192.168.2.1 #这里的网关要与之前配置VMnet8中设置的网关相同

Change setting
Restart network service after modification

service network restart

5 Verify that the configuration is successful

ip addr

It can be seen that the IP in ens33 has been set to 192.168.2.2 to
Verify configuration
test whether the virtual machine can connect to the external network

ping www.baidu.com

There is data returned, indicating that it can be connected.
Connect to the external network
Enter the cmd of the host to test whether the host can connect to the virtual machine

ping 192.168.2.2

There is data returned, indicating that it can be connected
Connect to the virtual machine

Guess you like

Origin blog.csdn.net/Tiezhu_Wang/article/details/113822362