Detailed explanation of three network connection modes of VMware virtual machine

Detailed explanation of three network connection modes of VMware virtual machine

Vmware provides three network working modes: (1) Bridged (bridge mode); (2) NAT (network address translation mode); (3) Host-Only (host only mode).

1. View the network connection mode of the VMware virtual machine

Open the vmware virtual machine, click [Edit] ===> [Virtual Network Editor] in the menu bar to open the window as shown in the figure:

Insert picture description here

You can see three network connection modes: bridge mode, host-only mode, and NAT mode. 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.

Among them, there are two virtual network cards corresponding to the host, VMware Network Adapter VMnet1 and VMware Network Adapter VMnet8, which act in host-only mode and NAT mode respectively. As shown below:

Insert picture description here

2. Bridged (bridge mode)

The bridge mode is to use the virtual bridge to communicate between the host network card and the virtual machine virtual network card. Similar to virtualizing the physical host as a switch, all virtual machines set up by bridging are connected to an interface of the switch, and the physical host is also plugged into the switch. The bridge mode connects the network card on the host with the virtual switch Vmnet0 through the virtual bridge. The virtual network card on the virtual machine is connected to the virtual switch Vmnet0, so the virtual machine IP in the bridge mode must be in the same network segment and subnet as the host The mask, gateway and DNS should also be consistent with the host network card.

In the bridge mode, the operating system virtualized by VMWare is like an independent host in the LAN. It can access any host in the LAN, and any host in the LAN can also access it. Application scenario: The current virtual machine provides access services for users on the entire LAN, and other LAN users can access the current host.

The bridge mode configuration process is as follows:

1. Set the network connection mode of the virtual machine network card

In the VMWare virtual machine, click [Virtual Machine] ===> [Settings], then click [Network Adapter], and [Network Connection] select [Bridge Mode (B): Directly Connected to Physical Network]. As shown below:

Insert picture description here

2. View the network configuration information of the host

Double-click the network card connected to the network in the [Network Connection] of the host, and click [Details] to view the host's IP address, DNS, gateway and other information. As shown below:

Insert picture description here

3. Set the network configuration of the virtual machine

Edit the network card configuration file of the virtual machine: /etc/sysconfig/network-scripts/ifcfg-eth0

[root@wgx ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

  1 DEVICE=eth0            ##网卡设备名称
  2 HWADDR=00:0C:29:11:14:33
  3 TYPE=Ethernet
  4 UUID=de465526-8150-4d27-9adb-1b21fa7b8da4
  5 ONBOOT=yes             ##自动加载
  6 NM_CONTROLLED=yes
  7 BOOTPROTO=static       ##手工设置网络信息
  8 
  9 IPADDR=192.168.1.201   ##和主机在同一个网段
 10 PREFIX=24              ##和主机的子网掩码相同
 11 GATEWAY=192.168.1.1    ##和主机的网关相同
 12 DNS1=192.168.1.1       
 13 DNS2=8.8.8.8

4. Restart the network service and test

[root@wgx ~]# service network restart
正在关闭接口 eth0:                                        [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 eth0: Determining if ip address 192.168.1.201 is already in use for device eth0...
                                                           [确定]
[root@wgx ~]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_seq=1 ttl=44 time=107 ms
64 bytes from 61.135.169.121: icmp_seq=2 ttl=44 time=87.1 ms
64 bytes from 61.135.169.121: icmp_seq=3 ttl=44 time=86.7 ms
64 bytes from 61.135.169.121: icmp_seq=4 ttl=44 time=103 ms
64 bytes from 61.135.169.121: icmp_seq=5 ttl=44 time=100 ms
^C
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4640ms
rtt min/avg/max/mdev = 86.773/97.193/107.515/8.631 ms

5. Use remote tools to connect to the virtual machine

Xshell 6 (Build 0175)
Copyright (c) 2002 NetSarang Computer, Inc. All rights reserved.

Type `help' to learn how to use Xshell prompt.
[D:\~]$ 

Connecting to 192.168.1.201:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Thu Apr 16 05:17:06 2020 from 192.168.1.102
[root@wgx ~]# 

3. NAT (Address Translation Mode)

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.

When connecting to the Vmnet8 virtual switch, the virtual machine connects the virtual NAT device and the virtual DHCP server to the Vmnet8 virtual switch, and also connects the virtual network card VMWare Network Adapter Vmnet8 on the host to the Vmnet8 virtual switch. The network card VMWare Network Adapter Vmnet8 is only used as an excuse for the communication between the host and the virtual machine, and the virtual machine does not rely on the network card VMWare Network Adapter Vmnet8 to network.

The virtual machine uses the NAT function to access the public network through the network where the host machine is located. Using the NAT mode, the virtual machine can access the Internet. The TCP/IP configuration information of the virtual machine in NAT mode is provided by the DHCP server of the VMnet8 virtual network. Other real hosts in the LAN will not be able to access the virtual machine, but other virtual machines on the same network segment can access it. It can be understood as the broadband of our own home, you can access Baidu, but other people cannot access you. Application scenario: Just go online through the virtual machine, other users cannot access your virtual machine.

The NAT mode configuration process is as follows:

1. Configure NAT and DHCP

Open the vmware virtual machine, click [Edit] in the menu bar =>【Virtual Network Editor】=>[NAT Mode], open the window as shown in the figure:

Insert picture description here

Click the [NAT Settings] button, as shown in the figure below:

Insert picture description here

Click the [DHCP Settings] button, as shown in the figure below:

Insert picture description here

2. Set the network connection mode of the virtual machine network card

In the VMWare virtual machine, click [Virtual Machine] ===> [Settings], then click [Network Adapter], [Network Connection] select [NAT Mode (N): used to share the host's IP address]. As shown below:

Insert picture description here

3. Set the network configuration of the virtual machine

Edit the network card configuration file of the virtual machine: /etc/sysconfig/network-scripts/ifcfg-eth0

[root@wgx ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 

  1 DEVICE=eth0
  2 HWADDR=00:0C:29:11:14:33
  3 TYPE=Ethernet
  4 UUID=de465526-8150-4d27-9adb-1b21fa7b8da4
  5 ONBOOT=yes
  6 NM_CONTROLLED=yes
  7 BOOTPROTO=dhcp

4. Restart the network service and check the network configuration information

[root@wgx ~]# service network restart
正在关闭接口 eth0:                                        [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 eth0: 
正在决定 eth0 的 IP 信息...完成。
                                                           [确定]
[root@wgx ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:11:14:33  
          inet addr:192.168.220.128  Bcast:192.168.220.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe11:1433/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9769 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3889 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:746679 (729.1 KiB)  TX bytes:325301 (317.6 KiB)

5. Test the network

[root@wgx ~]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_seq=1 ttl=128 time=79.0 ms
64 bytes from 61.135.169.121: icmp_seq=2 ttl=128 time=79.1 ms
64 bytes from 61.135.169.121: icmp_seq=3 ttl=128 time=71.3 ms
64 bytes from 61.135.169.121: icmp_seq=4 ttl=128 time=77.0 ms
64 bytes from 61.135.169.121: icmp_seq=5 ttl=128 time=71.4 ms
^C
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4511ms
rtt min/avg/max/mdev = 71.347/75.605/79.146/3.524 ms

6. Use remote tools to connect to the virtual machine

Xshell 6 (Build 0175)
Copyright (c) 2002 NetSarang Computer, Inc. All rights reserved.

Type `help' to learn how to use Xshell prompt.
[D:\~]$ 

Connecting to 192.168.220.128:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Thu Apr 16 11:48:39 2020 from 192.168.220.1
[root@wgx ~]# 

Note: The virtual network card VMWare Network Adapter Vmnet8 on the host is used for communication between the virtual machine and the host. If the network card is disabled, the remote connection tool on the host will not be able to connect to the virtual machine.

4. Host-Only (host mode only)

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 Host-Only mode separates the virtual machine from the external network, making the virtual machine a An independent system can only communicate with the host.

The Host-Only mode connects the virtual switch VMnet1 through the virtual network card VMWare Network Adapter VMnet1 of the host, so as to achieve the purpose of communicating with the virtual machine. If you want to network in Host-Only mode, you can share the host network card that can be connected to VMWare Network Adapter VMnet1 to realize virtual machine networking.

The configuration process of Host-Only mode is basically the same as NAT mode.

Guess you like

Origin blog.csdn.net/weixin_44377973/article/details/105560269