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
2 Configure the address parameters of NAT mode
Edit—virtual network adapter—change settings
Select VMnet8—uncheck "Use local DHCP service to assign IP addresses to virtual machines"—fill in the subnet IP (custom)—click NAT settings to
modify the gateway IP (here set to 192.168.2.1 )
3 Configure host VMnet8 address parameters
Open the settings, find "Network and Internet", click "Change adapter options" to
find VMnet8, right-click the properties, select the properties of IPV4, and change the IP address as follows
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 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中设置的网关相同
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
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.
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