How to configure Internet access for virtual machines in VMware (Linux system as an example)

Author: chenhao
virtual machine access must first understand the VMware virtual machine in three network models
a bridge mode:

  1. In this mode, the IP addresses of the physical network card and the virtual network card are in the same network segment, and the subnet mask, gateway, DNS and other parameters are the same.

2. The local physical network card and the virtual network card are bridged through the VMnet0 virtual switch. The virtual machine and the host are located at both ends of the virtual switch VMnet0. This switch makes the two ends in the same network segment.

3. Each virtual system in VMware is equivalent to an independent host. In the bridge mode, the host and the virtual machine are equivalent to two computers in the same LAN, and the virtual machine and the host are in the same position. In this case, the host and the virtual machine need to be able to communicate and need to be on the same network segment. This requires manual configuration of the IP address and subnet mask of the virtual system to ensure that the virtual machine and the host machine are on the same network segment. As an independent host, the virtual machine can communicate with any computer in the LAN.
2. Network address translation mode (NAT)
1. No manual configuration is required. Network configuration information such as IP address is provided by the DHCP server of the VMnet8 (NAT) virtual network. As long as the host can access the Internet, the virtual machine can realize network connection. The host's virtual network card VMware Network Adapter VMnet8 and the IP address of the virtual machine virtual network card are in the same network segment, and the subnet mask, gateway, DNS and other parameters are the same, while the host's real physical network card (host is equivalent to a router) and virtual The IP address of the machine is not in the same range.

2. The virtual system is in a virtual NAT network, and the virtual machine virtualizes a NAT server so that the virtual network card can connect to the Internet. In this connection mode, the guest uses the VMnet8 virtual switch. You can see the VMware NetworkAdapter VMnet8 virtual network card in the network sharing center of the host. This virtual network card is connected to the VMnet8 virtual switch to communicate with the virtual network card of the virtual system, that is, its The function is to allow the host to communicate with the VMnet8 network segment, but not to provide routing for the VMnet8 network segment. The guest can still access the Internet without this virtual network card, but the host can no longer access the VMnet8 network segment, that is, the host and the virtual machine can no longer communicate.

3. The IP address of the VMware Network Adepter VMnet8 virtual network card is specified by the system when VMware is installed. The network segment where the virtual machine virtualized NAT network is located is the same as the network segment where the VMware Network AdepterVMnet8 virtual network card is located, so The two virtual network cards of the host and the virtual machine can communicate normally.

4. In NAT mode, although the virtual machine is in the internal LAN, it can access the external network, because at this time the host computer is equivalent to a router with DHCP function turned on, and the real physical network card of the host (ie NAT device) Connected to the Network, the virtual machine is equivalent to a real host in the LAN, so the virtual machine can dynamically obtain network parameters through the host computer's DHCP, which is equivalent to a computer connected to the external Internet through a router. The host machine can access the virtual machine, but other hosts in the LAN cannot access the virtual machine, because the NAT network is in a virtual network provided by vmware. (Ssh can be implemented)
3. Host mode (host-only)
1. In this mode, all virtual systems can communicate with each other, but the virtual network where the virtual system is located and the real network where the host is located are actually Isolated. Although isolated, the virtual system and the host can communicate in this mode, which is equivalent to two machines directly connected by a twisted pair. At this time, the host no longer provides routing services for the virtual machine, so the virtual machine cannot communicate with the external network communication.

2. VMware Network Adepter VMnet1 is the virtual network card used by the Host to communicate with the Host-Only virtual network, but the Host-Only network does not have NAT service, so the virtual network cannot be connected to the external Internet. The virtual network formed between virtual machines The network is a fully enclosed network, and the only connection with the outside is that the virtual machine can communicate with the host.

3. The IP address of the VMware Network Adepter VMnet1 virtual network card is also specified by the VMware system. The VMware Network Adepter VMnet1 virtual network card and the virtual network card of the virtual machine are in the same network segment. In this mode, the physical network card and the virtual machine virtual network card are not in the same network segment.

Note: The NAT mode is very similar to the host mode. The main difference is that the host machine no longer has the NAT function in the host mode, that is, it is no longer equivalent to a router for virtual machines to access the Internet.
Insert picture description here
VMnet0: used for the virtual switch under the virtual bridge network

VMnet1: used for the virtual switch under the virtual Host-Only network

VMnet8: used for virtual switch under virtual NAT network

VMware Network Adepter VMnet1: The virtual network card used by the Host to communicate with the Host-Only virtual network

VMware Network Adepter VMnet8: Virtual network card used by Host to communicate with NAT virtual network

VMnet8 and VMnet1 provide DHCP services, but VMnet0 virtual network does not.

Take the bridge mode as an example, configure the virtual machine to go online
1. First we need to make sure that the local computer can connect to the external network, and then open the installed virtual machine
Insert picture description here
2. Execute the command ifconfig to view the current virtual machine's IP, the default system is automatically obtained.
Insert picture description here
This picture is the picture
3 after I changed the configuration. The local computer is surfing the Internet with a static address configured, so you need to modify the IP address of the network card, you can use the command:
vi /etc/sysconfig/network-scripts/ifcfg-ens33. Open this interface.

vi /etc/sysconfig/network-scripts/ifcfg-ens33

Insert picture description here
The figure is also a screenshot after the configuration is changed. The red box is the configuration after the modification.
4. The system defaults to obtain it automatically. You need to modify the address and the IP of the local computer to the same network segment.

ONBOOT=yes
BOOTPROTO=static
IPADDR=116.228.47.157
NETMASK=255.255.255.0
GATEWAY=116.228.47.145

The system configuration must be the same network segment IP as the local computer, and the gateway must be the same.
5. After the network card is configured, restart the network card and execute the command: /etc/init.d/network restart

/etc/init.d/network restart

Insert picture description here
6. After restarting, check the ip address, command ifconfig to check the IP of all network cards of the current server.
Insert picture description here
7. Finally configure DNS, execute the command, vi /etc/resolv.conf and open the directory where you are:
Add the following two server addresses in it:

nameserver 202.106.0.20
nameserver 8.8.8.8

Insert picture description here
8. After the configuration is complete, test whether you can ping www.baidu.com online
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_52425873/article/details/112646840