In CentOS 7, configure the static IP address and centosnat in NAT mode.
CentOS 7 virtual machine has been installed in Vmware and NAT mode is selected
Automatically obtain IP commands
dhclient
View IP addresses
ip add
The following information is available:
ens33:
inet 192.168.150.128/24
This is the IP address of my VM
In VMware, choose "edit"> "Virtual Network Editor"> "VMnet8" from the menu bar, and click "NAT Settings" below to view the gateway IP address.
My gateway IP Address: 192.168.150.2
View the files in/etc/sysconfig/network-scripts (press the Tab twice)
ls /etc/sysconfig/network-scripts/ifcfg-ens33
Edit ifcfg-ens33
vi /etc/sysconfig/network-scripts/ifcfg-ens33
Press I to enter the editing mode.
Modify the following content
BOOTPROTO=static
Set to static
ONBOOT=yes
Load the NIC information when starting the Virtual Machine
IPADDR=192.168.150.128NETMASK=255.255.255.0GATEWAY=192.168.150.2DNS1=119.29.29.29
The above is my IP information, which is viewed earlier
Press Esc and enter: wq to save and exit.
Restart NETWORK SERVICE
systemctl restart network.service
View IP addresses
ifconfig
View route table
route -n
Ping connectivity test
ping www.baidu.com
Windows CMD input command
ping 192.168.150.128
Ping indicates that the physical machine and virtual machine can communicate with each other.
If the VM does not contain the ifconfig command
First, make sure that the virtual machine can be connected to the Internet.
Enter yum install-y net-tools