Windows 或 Linux平台搭建网关服务器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/IKQMKSQM/article/details/81429719

网关服务器的常见用途:
1.企业局域网想要访问外网,可以使用网关服务器上网
2.可以一个网卡连接公网,一个网卡连接局域网交换机,让网关服务器做路由器使用

Windows 平台

服务端平台:Windows 7(服务端必须有两张网卡) 客户端平台:Windows 10
外网IP:192.168.111.0/24 内网IP:192.168.222.0/24

1. 外网适配器打开共享.

外网适配器设置

这里有一点要注意,外网打开允许其他用户连接后,内网的IP地址会自动改变,这时候得手动修改一下内网适配器的IP地址.

2. 内网机器设置

网关设置成服务器的内网IP

已经可以正常上网这里写图片描述

注意:
内网适配器的固定IP不要填写网关,否则会导致路由混乱.

在Linux平台搭建(使用iptables)

这里服务端平台用Centos 7 1804版本,客户端用的是Win7
外网IP:192.168.111.0/24 内网IP:192.168.222.0/24

1. 关闭firewalld,打开iptables服务

systemctl stop firewalld
systemctl mask firewalld
安装iptables-services
yum install iptables-service
设置开机启动防火墙
systemctl enable iptables

2. 开启内核转发

vim /etc/sysctl.conf
添加一条net.ipv4.ip_forward = 1

3. 配置iptables

iptables -t nat -A POSTROUTING -s 192.168.222.0/24 -j MASQUERADE

4.保存&重启iptables

service iptables save
service iptables restart

猜你喜欢

转载自blog.csdn.net/IKQMKSQM/article/details/81429719