Three network modes of VMware virtual machine [Host-Only, Bridged, NAT]

01. NAT (Address Translation Mode)

Generally, the virtual machine is connected to the Internet, it is simple to use the bridge mode to configure, but if your network environment is lack of ip resources or strict ip management, then the bridge mode is not suitable, and we need to network.

01. What is NAT mode

NAT mode uses virtual NAT devices and virtual DHCP servers to enable virtual machines to be networked. The network structure is shown in the following figure:
Insert picture description here
In the NAT mode, the host network card is directly connected to the virtual NAT device, and then the virtual NAT device and the virtual DHCP server are connected to the virtual switch VMnet8, thus realizing virtual machine networking. Our VMware Network Adapter VMnet8 virtual network card is mainly for the communication between the host and the virtual machine.

01. How to set NAT mode

Set the options of NAT mode in the virtual machine, open vmware, click "Virtual Network Editor" under "Edit", and set NAT parameters and DHCP parameters.
Insert picture description here
Insert picture description here
Insert picture description here
Change the network connection mode of the virtual machine to NAT mode, and click "Edit virtual machine settings".
Insert picture description here
Click "Network Adapter", select "NAT Mode" to
Insert picture description here
start the system, edit the network card configuration file, the command is vi /etc/sysconfig/network-scripts/ifcfg-eth0 After
Insert picture description here
editing, save and exit, and then restart the virtual machine network card to dynamically obtain ip address

If I execute the ifconfig command, I cannot get the ip dynamically?

  • First, make sure that the host ADSL can access the Internet normally. In the control panel-management tools-services, start "VMware DHCP Service" "VMware NAT Service" (Because the VMware service slows down the system, I changed the service to manual , Restart when needed)
    Insert picture description here

  • Execute the command dhclient eth0

  • Execute the command ifconfig and find that you can see ip

03. Test

Use the ping command to ping the external network ip to test whether it can be connected to the Internet.
Insert picture description here
Disable VMware Network Adapter VMnet8
Insert picture description here
Insert picture description here
Insert picture description here
virtual machine can connect to the external network, but the virtual machine and physical machine cannot communicate. After enabling VMware Network Adapter VMnet8, it is found that the remote tool can connect to the virtual machine.

02. Bridged (bridge mode)

vmware provides us with three network working modes, they are: Bridged (bridge mode), NAT (network address translation mode), Host-Only (host only mode) .

Open the vmware virtual machine, we can see VMnet0 (bridge mode), VMnet1 (host mode only), VMnet8 (NAT mode) in the "Virtual Network Editor" under "Edit" in the option bar.

  • VMnet0 represents a virtual switch used in bridge mode;

  • VMnet1 represents a virtual switch used in host-only mode;

  • VMnet8 represents a virtual switch used in NAT mode.

Insert picture description here
At the same time, we can see these two virtual network cards in the "network connection" of the host,

  • VMware Network Adapter VMnet1 works in host-only mode, used to realize communication between virtual machines and physical machines, and has nothing to do with networking. Its networking requires the sharing of physical network cards to get online

  • VMware Network Adapter VMnet8 acts in the NAT mode, used to realize the communication between virtual machines and physical machines, and has nothing to do with networking. It uses virtual nat for networking

  • If you uninstall these two pieces, you can click "Restore Default Settings" in the "Virtual Network Editor" under "Edit" of vmware to restore the virtual network card again

Why is there no VMware Network Adapter VMnet0 virtual network card on the physical machine? Because the bridge mode is to communicate and network through a virtual bridge, there is no need for a virtual network card to make the virtual machine and the physical machine communicate.

Insert picture description here

01. What is bridge mode

The bridge mode is to use the virtual bridge to communicate between the host network card and the virtual machine network card. Under the effect of bridging, it is similar to virtualizing the physical host as a switch. All virtual machines set by bridging are connected to an interface of this switch. The physical host is also plugged into this switch, so all network cards and network cards under the bridge are connected. It is in exchange mode and can be accessed without interference.

In the bridge mode, the virtual machine ip address needs to be in the same network segment as the host. If networking is required, the gateway and DNS need to be consistent with the host network card. The network structure is shown below:

Insert picture description here

02. How to set the bridge mode

First, after installing the system, click "Edit Virtual Machine Settings" to set the network card mode before turning on the system.
Insert picture description here
Click "Network Adapter", select "Bridge Mode", and then "OK"
Insert picture description here
Before entering the system, let's confirm the host's ip address, gateway, DNS and other information.
Insert picture description here
Then, enter the system to edit the network card configuration file, the command is vi /etc/sysconfig/network-scripts/ifcfg-eth0 After
Insert picture description here
editing, save and exit, and then restart the virtual machine network card

03. Test

Use the ping command to ping the external network ip to test whether the network can be connected.

Insert picture description here
It can ping the external network ip to prove that the bridge mode is set successfully. Use remote tools to test the communication between the host and the virtual machine.
Insert picture description here
The communication between the host and the virtual machine is normal.

02. Host-Only (Host mode only)

The Host-Only mode is for security considerations. The Host-Only mode separates the virtual machine from the external network, making the virtual machine an independent system that only communicates with the host.

If you want to enable the virtual machine to be networked, we can share the host network card to the VMware Network Adapter VMnet1 network card to achieve the purpose of virtual machine networking.

01. What is Host-Only Mode

The Host-Only mode actually removes the virtual NAT device in the NAT mode, and then uses the VMware Network Adapter VMnet1 virtual network card to connect to the VMnet1 virtual switch to communicate with the virtual machine. The network structure is shown in the following figure:
Insert picture description here

02. How to set the Host-Only mode

First set up the "Virtual Network Editor", you can set the starting range of DHCP.
Insert picture description here
Set the virtual machine to Host-Only mode.
Insert picture description here
Power on the system, and then set the network card file, restart the network card configuration information to take effect.
Insert picture description here

03. Test

Use remote tools to test whether you can communicate with the host.
Insert picture description here
The host and the virtual machine can communicate, and now the virtual machine is set to communicate with the external network. Modify the DHCP subnet and start address of the virtual machine, and click "Virtual Network Editor".
Insert picture description here
Reconfigure the network card and use the VMware Network Adapter VMnet1 virtual network card as the route of the virtual machine.
Insert picture description here
Restart the network card, and then use the remote tool to test whether it can connect to the external network and communicate with the host.
Insert picture description here
The test results prove that the virtual machine can be connected to the external network.

The above 192.168.137.1 can be other, which can avoid repeated setting of virtual machine ip and network segment and dhcp segment in the network editor. The above is the IP obtained automatically, you can also set a fixed IP by yourself.

Guess you like

Origin blog.csdn.net/qq_42226855/article/details/111874973