内网服务器共享上网

1,在批量服务器m01上执行
第一个历程:内网172.16.1.0网段内网通过10.0.0.61进行转发

iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -j SNAT --to 10.0.0.61

第二个历程:外网机器上打开转发

echo "net.ipv4.ip_forward = 1" >>/etc/sysctl.conf
sysctl -p

2,在内网机器上,更改其网关为 10.0.0.61

vim /etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY=10.0.0.61

最后重启网络服务即可。

systemctl restart network

最后的现象:(从61跳转到外网)

PING baidu.com (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=128 time=21.2 ms
From gateway (10.0.0.61) icmp_seq=2 Redirect Host(New nexthop: 10.0.0.254 (10.0.0.254))
From gateway (10.0.0.61): icmp_seq=2 Redirect Host(New nexthop: 10.0.0.254 (10.0.0.254))
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=128 time=26.1 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=128 time=33.0 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=4 ttl=128 time=23.2 ms
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容