Use bridge mode to make virtual machines\notebooks\linux desktops communicate with each other

1. Environment:

Network environment: home WIFI
windos-notebook (built-in VM virtual machine) (WIFI connection)
linux desktop (connected to router)

2. Connection mode

1. Bridge mode

The bridge mode is to use the virtual bridge of the virtual machine to communicate with the physical network card of the host. At this time, the virtual machine and the physical host are equivalent to being in the same LAN, and the IP addresses they use are also in the same network segment. Other IPs being the same will cause conflicts, and this method is suitable for network environments where IP address allocation is relatively generous.

2. Host sharing mode

The virtual machine communicates directly with the host's network card through the VMnet1 virtual network card. This method isolates the virtual machine from the external network. It can only access virtual machine resources through the physical host, and the virtual machine cannot access Internet resources. This mode Suitable for learning and testing in complex network environments

3. NAT mode

In NAT mode, the host network card is directly connected to the virtual NAT device of the virtual machine, and then the virtual machine's NAT device and the virtual DHCP server of the virtual machine are connected to the virtual network card VMnet8. At this time, the virtual machine and the physical host are not in the same local area network. It mainly communicates with the host through the VMnet8 virtual network card. This method is suitable for network environments where IP address allocation is relatively tight.

3. Configuration

1. Laptop WIFI network configuration

( focus on IPv4, subnet mask, default gateway )
insert image description here

2. VM Configuration

insert image description here

3. Virtual machine configuration

3.1. First look at the network information and make sure to modify ens33

[root@localhost network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.6  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::ff54:2cd1:1e62:3bb7  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:c6:6a:c2  txqueuelen 1000  (Ethernet)
        RX packets 2483  bytes 227437 (222.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3267  bytes 1025503 (1001.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 4  bytes 336 (336.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 336 (336.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost network-scripts]#

3.2. Modify ens33

Focus on:
the following configuration, if there is, modify it, if not, add
BOOTPROTO //for static
ONBOOT //for yes
IPADDR
NETMASK
GATEWAY
DNS1 //for 8.8.8.8

[root@localhost network-scripts]# cat ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=53274cc6-1b66-4fd5-9568-1ecd2e0b06a3
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.3.6
PREFIX=24
GATEWAY=192.168.3.1
DNS1=8.8.8.8
IPV6_PRIVACY=no
[root@localhost network-scripts]#

3.3. Restart the network

systemctl restart network

4. Test

Laptop ping virtual machine ----- pass

C:\Users\Administrator>ping 192.168.3.6
正在 Ping 192.168.3.6 具有 32 字节的数据:
来自 192.168.3.6 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.3.6 的回复: 字节=32 时间=1ms TTL=64
来自 192.168.3.6 的回复: 字节=32 时间=2ms TTL=64
来自 192.168.3.6 的回复: 字节=32 时间=1ms TTL=64
192.168.3.6 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 2ms,平均 = 1ms

Virtual machine ping notebook ----- pass

[root@localhost network-scripts]# ping 192.168.3.8
PING 192.168.3.8 (192.168.3.8) 56(84) bytes of data.
64 bytes from 192.168.3.8: icmp_seq=1 ttl=128 time=0.290 ms
64 bytes from 192.168.3.8: icmp_seq=2 ttl=128 time=2.29 ms
64 bytes from 192.168.3.8: icmp_seq=3 ttl=128 time=1.17 ms
^C
--- 192.168.3.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.290/1.255/2.299/0.823 ms
[root@localhost network-scripts]#

Virtual machine ping baidu.com-----communication

[root@localhost sysconfig]# ping baidu.com
PING baidu.com (110.242.68.66) 56(84) bytes of data.
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=1 ttl=53 time=50.7 ms
From 192.168.3.8 (192.168.3.8): icmp_seq=2 Redirect Network(New nexthop: gateway (192.168.3.1))
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=2 ttl=53 time=47.0 ms
From 192.168.3.8 (192.168.3.8): icmp_seq=3 Redirect Network(New nexthop: gateway (192.168.3.1))
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=3 ttl=53 time=43.4 ms
From 192.168.3.8 (192.168.3.8): icmp_seq=4 Redirect Network(New nexthop: gateway (192.168.3.1))
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=4 ttl=53 time=45.4 ms
From 192.168.3.8 (192.168.3.8): icmp_seq=5 Redirect Network(New nexthop: gateway (192.168.3.1))
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=5 ttl=53 time=44.7 ms
^C
--- baidu.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4008ms
rtt min/avg/max/mdev = 43.445/46.302/50.797/2.538 ms
[root@localhost sysconfig]#

5. Error resolution

5.1 Phenomena

When the virtual machine pings Baidu, an error message is reported:

From 192.168.3.8 (192.168.3.8): icmp_seq=4 Redirect Network(New nexthop: gateway (192.168.3.1))

5.2 Solutions

Configure the notebook WIFI sharing method as follows
insert image description here

5.3 Results

[root@localhost sysconfig]# ping baidu.com
PING baidu.com (110.242.68.66) 56(84) bytes of data.
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=1 ttl=53 time=47.3 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=2 ttl=53 time=43.1 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=3 ttl=53 time=43.3 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=4 ttl=53 time=43.9 ms
^C
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 43.164/44.450/47.346/1.696 ms
[root@localhost sysconfig]#

Guess you like

Origin blog.csdn.net/eettttttt/article/details/131882353