开启IP伪装
1 2 |
[root@m01 ~]# firewall-cmd --add-masquerade success |
开启内核转发
1 2 3 4 5 6 7 8 9 10 11 12 |
注意这一步只有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 |
配置内网机器的网关地址
1 2 3 4 5 6 7 |
[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 |
测试访问外网
1 2 3 4 5 6 |
[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 |