基于linux下的网关实验

网关:路由器上和自己有相同网段的接受网卡发送的数据IP。

网关实验就是让真机变为路由器,在虚拟机进行连接。

[[email protected] Desktop]$ su - root        密码westos

[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0    删除网关

[[email protected] ~]# 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

[[email protected] ~]# systemctl restart network   重启网络   连接wifi查看网关。

基于linux下的网关实验

[[email protected] ~]# 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

[[email protected] ~]# ping www.baidu.com    可以连接的上百度

[[email protected] ~]# systemctl start firewalld        开始防火墙

[[email protected] ~]# firewall-cmd --add-masquerade   

success

[[email protected] ~]# 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下的网关实验

实验排错步骤:

1、真机 ping www.baidu.com

基于linux下的网关实验

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下的网关实验基于linux下的网关实验基于linux下的网关实验