Windows 或 Linux平台搭建网关服务器
网关服务器的常见用途: 1.企业局域网想要访问外网,可以使用网关服务器上网 2.可以一个网卡连接公网,一个网卡连接局域网交换机,让网关服务器做路由器使用
#Windows 平台 服务端平台:Windows 7(服务端必须有两张网卡) 客户端平台:Windows 10 外网IP:192.168.111.0/24 内网IP:192.168.222.0/24 ##1. 外网适配器打开共享.
这里有一点要注意,外网打开允许其他用户连接后,内网的IP地址会自动改变,这时候得手动修改一下内网适配器的IP地址.
##2. 内网机器设置
已经可以正常上网
注意: 内网适配器的固定IP不要填写网关,否则会导致路由混乱.
Liunx服务端(用firewalld)
sudo vim /etc/sysctl.conf --- net.ipv4.ip_forward = 1
立即生效
sudo sysctl -p
firewall-cmd --permanent --zone=public --add-masquerade firewall-cmd --reload
firewall-cmd --query-masquerade
firewall-cmd --remove-masquerade
在Linux平台搭建(使用iptables)
这里服务端平台用Centos 7 1804版本,客户端用的是Win7 外网IP:192.168.111.0/24 内网IP:192.168.222.0/24
- 关闭firewalld,打开iptables服务 systemctl stop firewalld systemctl mask firewalld
- 安装iptables-services yum install iptables-service
- 设置开机启动防火墙 systemctl enable iptables
- 配置iptables iptables -t nat -A POSTROUTING -s 192.168.222.0/24 -j MASQUERADE
- 保存&重启iptables service iptables save service iptables restart