First open the network settings:
Start the virtual machine and use the nmcli command to view the basic network information of the current virtual machine
nmcli connection show
Shown as follows:
DEVICE: is the name of the network card
Set the network acquisition method of centos7 to automatically acquire ip
nmcli connection modify enp0s3 \
connection.autoconnect yes \
ipv4.method auto
nmcli connection up enp0s3
Then we tested and found that the network was connected