table of Contents
1. View the network segment
(1) Open the "Virtual Network Editor" of the virtual machine
(2) Select NAT mode→NAT settings
(3) Here you can see the network segment
Here you can see that the network segment is 192.168.184.0, so you can set the IP address of the virtual machine under this network segment. The gateway is set as shown in the figure.
2. Configure a static IP address
(1) Open the virtual machine, enter the terminal, and enter root;
(2) Find the network configuration file of your virtual machine
①Enter the following folder directory
# cd /etc/sysconfig/network-scripts/
②View the files in the folder
# ls
③ Mine is: ifcfg-ens32
(3) Modify the configuration file
①Open the configuration file
# vi ifcfg-ens32
②Enter "i" to start editing, and modify the following:
BOOTPROTO="static"
ONBOOT="yes"
IPADDR=192.168.184.114
GATEWAY=192.168.184.2
NETMASK=255.255.255.0
DNS1=192.168.184.2
DNS2=114.114.114.114
③After modifying, press Esc, enter ":wq", save and exit
(4) Restart the network
# service network restart
(5) Test whether the configuration is successful
# ping baidu.com
Output as shown in the figure below, which means the configuration is successful