网关:路由器上和自己有相同网段的接受网卡发送的数据IP。网关实验就是让真机变为路由器,保证真机可以连接网络的前提下,在虚拟机也可以上网

[root@foundation21 ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0   

[root@foundation21 ~]# route -n                查看网关

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

172.25.21.0     0.0.0.0         255.255.255.0   U     425    0        0 br0

172.25.254.0    0.0.0.0         255.255.255.0   U     425    0        0 br0

192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

[root@foundation21 ~]# systemctl restart network   重启网络   连接wifi查看网关。

基于linux下的网关实验_IP

[root@foundation21 ~]# route -n                    查看出来了新的网关

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

0.0.0.0         192.168.43.1    0.0.0.0         UG    600    0        0 wlp3s0

[root@foundation21 ~]# ping www.baidu.com    可以连接的上百度

[root@foundation21 ~]# systemctl start firewalld        开始防火墙

[root@foundation21 ~]# firewall-cmd --add-masquerade   开启伪装

success

[root@foundation21 ~]# ifconfig                      电脑变成了新的路由

br0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

        inet 172.25.254.21  netmask 255.255.255.0  broadcast 172.25.254.255

        inet6 fe80::221:ccff:fec7:da84  prefixlen 64  scopeid 0x20<link>

        ether 00:21:cc:c7:da:84  txqueuelen 0  (Ethernet)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

基于linux下的网关实验_vim_02

实验排错步骤:

1、真机 ping www.baidu.com

基于linux下的网关实验_vim_03

firewall-cmd --list-all  看是否为 yes

2、在虚拟机里面看ip网关dns

    ping 网关

3、真机操作这个问题:

   vim /etc/sysctl.conf

   ip_forward=1

   sysctl -p

4、在真机删除网关输入virt-manager进去打开desktop然后点运行灯泡形状,删除NIC:2a:ba:93然后建立network选择virtio出去打开desktop

5、在真机操作:

vim /etc/sysconfig/network

加入自己的ip,重启就行。

vim /etc/resolv.conf

基于linux下的网关实验_IP_04

基于linux下的网关实验_vim_05

基于linux下的网关实验_IP_06