firewalld共享上网

1.开启IP伪装

[root@m01 ~]# firewall-cmd --add-masquerade 
success

2.开启内核转发

注意这一步只有CentOS6系统需要做,CentOS7中默认已经开启。

#配置内核转发
[root@m01 ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1

#在CentOS6中开启之后生效命令
[root@m01 ~]# sysctl -p

#查看内核转发是否开启
[root@m01 ~]# sysctl -a|grep net.ipv4.ip_forward
net.ipv4.ip_forward = 1

3.配置内网机器的网关地址

[root@web01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1 
#添加以下两行
GATEWAY=172.16.1.61
DNS1=223.5.5.5

#重启网卡
[root@web02 ~]# ifdown eth1 && ifup eth1

4.测试访问外网

[root@web02 ~]# ping baidu.com
PING baidu.com (39.156.69.79) 56(84) bytes of data.
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=127 time=33.3 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=127 time=31.1 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=3 ttl=127 time=39.8 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=4 ttl=127 time=30.9 ms

 

posted @ 2020-09-16 15:24  六月OvO  阅读(246)  评论(0编辑  收藏  举报