Loading

CentOS7 通过snat进行上网

需求:

有两台服务器,一台绑定了弹性公网IP,另外一台没有,需要内网服务器通过有弹性ip的机器代理进行上网。

环境:

centos7 操作系统
服务器A: 192.168.0.18 (可以上网,有弹性公网IP)
服务器B:192.168.0.17 (无法上网)

1、 分别centos7上的3台主机上关闭firewad和清空iptables的nat

$ systemctl stop firewalld
$  iptables  -F

2、代理(服务器A)上打开内核转发

$ echo 1  >/proc/sys/net/ipv4/ip_forward
$ sysctl -p /etc/sysctl.conf  

3、 在服务器A上做SNAT源地址转换规则

$  iptables -t nat -A POSTROUTING  -s 192.168.0.0/24 -j SNAT --to-source 192.168.0.18

4、在内网的机器(服务器B)上删除原网关,添加内网的网关

$ yum install -y net-tools
$ route delete default gw 192.168.0.1
$ route add default gw 192.168.0.18

5、服务器B重启后失效,重新执行第④步

posted @ 2020-11-18 09:20  亚里士多智  阅读(655)  评论(0编辑  收藏  举报