Blind cat meets dead mouse, I'm not sure this connection must be right
note!
The IP of 192.168.43.173
my real host is connected to wifi. My bridge is set. The 192.168.43.23
virtual machine is set. The 192.168.43.123
virtual machine can only connect to the external network through the bridge.
[root@westos ~]# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.43.23 netmask 255.255.255.0 broadcast 192.168.43.255
inet6 fe80::d422:d4ff:fe9d:77e9 prefixlen 64 scopeid 0x20<link>
ether e8:6a:64:71:b6:a2 txqueuelen 1000 (Ethernet)
RX packets 3743 bytes 352371 (344.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2332 bytes 1837525 (1.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp8s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether e8:6a:64:71:b6:a2 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
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 704 bytes 65916 (64.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 704 bytes 65916 (64.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:34:57:c0 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:fe47:612b prefixlen 64 scopeid 0x20<link>
ether fe:54:00:47:61:2b txqueuelen 1000 (Ethernet)
RX packets 1290 bytes 154313 (150.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1079 bytes 837552 (817.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.43.173 netmask 255.255.255.0 broadcast 192.168.43.255
inet6 fe80::2fb7:5c4b:a4e8:7db3 prefixlen 64 scopeid 0x20<link>
inet6 240e:454:2c0:d0c7:cec0:9ffa:9d3d:f1b5 prefixlen 64 scopeid 0x0<global>
ether f8:a2:d6:d2:7a:93 txqueuelen 1000 (Ethernet)
RX packets 11026 bytes 6591003 (6.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11173 bytes 1795766 (1.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- step1
First turn on the firewall地址伪装
function in the real host
[root@westos network-scripts]# firewall-cmd --permanent --add-masquerade
success
[root@westos network-scripts]# firewall-cmd --reload
success
[root@westos network-scripts]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: br0 enp8s0 wlp7s0
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
masquerade: yes
forward-ports:
source-ports:
icmp-blocks:
rich rules:
- step2
In the virtual machine, edit the configuration file of
the gateway/etc/sysconfig/network
Write in the configuration file of the gateway网桥的IP
[root@westoslinux ~]# cat /etc/sysconfig/network
# Created by anaconda
GATEWAY=192.168.43.23 //真实主机中网桥的IP地址
[root@westoslinux ~]# nmcli connection reload
[root@westoslinux ~]# nmcli connection down westos
Connection 'westos' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@westoslinux ~]# nmcli connection up westos
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
- step3
test: ping 14.215.177.38
[root@westoslinux ~]# ping 14.215.177.38
PING 14.215.177.38 (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38: icmp_seq=39 ttl=52 time=2428 ms
64 bytes from 14.215.177.38: icmp_seq=40 ttl=52 time=1404 ms
64 bytes from 14.215.177.38: icmp_seq=41 ttl=52 time=380 ms
64 bytes from 14.215.177.38: icmp_seq=42 ttl=52 time=54.0 ms
64 bytes from 14.215.177.38: icmp_seq=43 ttl=52 time=71.4 ms
64 bytes from 14.215.177.38: icmp_seq=44 ttl=52 time=69.6 ms
64 bytes from 14.215.177.38: icmp_seq=45 ttl=52 time=67.8 ms
64 bytes from 14.215.177.38: icmp_seq=46 ttl=52 time=65.5 ms
64 bytes from 14.215.177.38: icmp_seq=47 ttl=52 time=73.2 ms
64 bytes from 14.215.177.38: icmp_seq=48 ttl=52 time=62.7 ms
64 bytes from 14.215.177.38: icmp_seq=49 ttl=52 time=60.8 ms
64 bytes from 14.215.177.38: icmp_seq=73 ttl=52 time=1082 ms
64 bytes from 14.215.177.38: icmp_seq=74 ttl=52 time=73.3 ms
64 bytes from 14.215.177.38: icmp_seq=75 ttl=52 time=73.5 ms
64 bytes from 14.215.177.38: icmp_seq=76 ttl=52 time=80.1 ms
64 bytes from 14.215.177.38: icmp_seq=77 ttl=52 time=70.4 ms
64 bytes from 14.215.177.38: icmp_seq=78 ttl=52 time=75.4 ms
64 bytes from 14.215.177.38: icmp_seq=79 ttl=52 time=67.5 ms
64 bytes from 14.215.177.38: icmp_seq=80 ttl=52 time=141 ms
^C
--- 14.215.177.38 ping statistics ---
80 packets transmitted, 19 received, 76.25% packet loss, time 647ms
rtt min/avg/max/mdev = 54.036/336.883/2428.042/611.900 ms, pipe 3
- step4
edit DNS configuration file/etc/resolv.conf
[root@westoslinux etc]# vim resolv.conf
[root@westoslinux etc]# cat resolv.conf
nameserver 114.114.114.114
[root@westoslinux etc]# ping -c 4 www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=52 time=56.8 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=52 time=75.2 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=52 time=53.7 ms
64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=52 time=71.3 ms
--- www.a.shifen.com ping statistics ---
7 packets transmitted, 4 received, 42.8571% packet loss, time 39ms
rtt min/avg/max/mdev = 53.733/64.263/75.185/9.147 ms