When the network connection mode of the virtual machine is changed to bridge mode, ifconfig cannot see the IP address of the virtual machine and needs to be manually configured. Other modes can also set the IP to a static IP.
(1) View the gateway address of the virtual machine
#route -n
(2) Switch to the /etc/netplan/ directory, and set the IP address, gateway address, and DNS address of the physical network card of the virtual machine (make sure it is in the same network segment as the host machine, and the gateway address is set to the routing address of the LAN connected to the computer ). Pay attention to the alignment format of each line, there must be a space after the colon, otherwise an error will occur.
#cd /etc/netplan
#ls
#sudo vim 00-installer-config.yaml
You can use the ipconfig/all command in cmd to view the IP address of the DNS server of the wireless LAN connected to the computer.
(3) Make the set IP address take effect
#netplan apply
Restart the virtual machine.
Check whether the virtual machine can connect to the Internet: ping the external network address
It indicates that the virtual machine is successfully connected to the Internet.
Note: It is a study note, if there is any mistake, please correct me.