Install CentOS7 virtual machine
Configure network segment
Set the network segment in Edit ⇒ Virtual Network Editor. Set the network segment to 10.4.7.0, and the subnet mask to 255.255.255.0. In the
NAT Setting, set the gateway GATEWAY to 10.4.7.2.
NAT Settings
Statically set the IP address of the virtual machine
Open the virtual machine and edit the
contents of the file /etc/sysconfig/network-scripts/ifcfg-ens33 as follows:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=8f9e347a-9d38-4fc1-ae26-ae464cbfdf12
DEVICE=ens33
ONBOOT=yes
IPADDR="10.4.7.11"
NETMASK="255.255.255.0"
GATEWAY="10.4.7.2"
DNS1="10.4.7.2"
Note:
BOOTPROTO=static, not the default static; to
set the DNS domain name resolution server, it can be set to the gateway address "10.4.7.2", or it can be set to 8.8.8.8 and 8.8.8.4, which are free domain names published by Google Resolution server.
DNS1="8.8.8.8"
DNS2="8.8.8.4"
Restart network service
systemctl restart network
Ping the host machine (10.4.7.1)
Ping www.baidu.com,
you can see that the virtual machine 10.4.7.11 can be connected to the host machine, and it can also resolve the domain name normally and connect to the external network.
note
Before net-tools is installed, commands such as ifconfig cannot be used. You can use ip addr
commands to view network information.