基于linux下的网关实验

网关:路由器上和自己有相同网段的接受网卡发送的数据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查看网关。

[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

实验排错步骤:

1、真机 ping www.baidu.com

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值