正向代理配置网关服务器

正向代理应用场景:

假设公司有同网段的多台服务器,只有一台服务器有外网,其他的机器没有外网,但是想让其他的机器也有网络,能用yum安装软件,这时候需要做一个正向代理服务器,去实现代理上网。

CentOS7 通过firewalld配置网关服务器

内网的网段为172.16.1.0/24

可访问外网的内网服务器的ip是172.16.1.41

内网接口是  ens37

1、在可以访问外网的服务器

首先添加ip_forward转发

vim /etc/sysctl.conf

net.ipv4.ip_forward=1

让添加内容生效
sysstl -p

2、转发内网段的流量,执行firewalld命令

先打开防火墙的服务,在执行以下操作

[root@ localhost ~]# firewall-cmd --add-masquerade --permanent 
success
[root@ localhost ~]# firewall-cmd --permanent --direct --passthrough ipv4 -t nat -I POSTRPUTING -o ens37 -j 
MASQUERADE -s 172.16.1.0/24
success
[root@ localhost ~]# firewall-cmd --reload
success

3、添加内网服务器网关(没有外网的服务器)

扫描二维码关注公众号,回复: 9104397 查看本文章
ifdown ens33

route add default gw 172.16.1.41 dev ens37  /临时生效

vim ifcfg-ens37

GATEWAY=有外网的机器ip

重启网卡

猜你喜欢

转载自www.cnblogs.com/security-guard/p/12299904.html