1. 程式人生 > >Windows 或 Linux平臺搭建閘道器伺服器

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

已經可以正常上網這裡寫圖片描述

注意:
內網介面卡的固定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