Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

CentOS 7/8 部署 PPTP VPN 服務端完整教程(含防火牆/轉發)

編輯:Linux 教學

環境準備

  • CentOS 7.x / 8.x (x86_64)
  • 公網 IP,root 權限
  • 關閉 SELinux 或設為 Permissive:setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=permissive/' /etc/selinux/config

一、安裝軟體包

yum -y install epel-release
yum -y install ppp pptpd iptables-services
# CentOS 8 需額外啟用 PowerTools
# dnf config-manager --set-enabled powertools

二、配置 PPTP

  1. /etc/ppp/options.pptpd:
    name pptpd
    refuse-pap
    refuse-chap
    refuse-mschap
    require-mschap-v2
    require-mppe-128
    proxyarp
    lock
    nobsdcomp
    novj
    novjccomp
    nologfd
    idle 2592000
    ms-dns 8.8.8.8
    ms-dns 8.8.4.4
  2. /etc/ppp/chap-secrets (用戶名/密碼):
    # client    server    secret          IP addresses
    vpnuser    pptpd     StrongPass123!  *
  3. /etc/pptpd.conf:
    option /etc/ppp/options.pptpd
    logwtmp
    localip 10.8.0.1
    remoteip 10.8.0.10-100
  4. 開啟 IP 轉發 /etc/sysctl.d/99-vpn.conf:
    net.ipv4.ip_forward = 1
    net.ipv4.conf.all.accept_redirects = 0
    net.ipv4.conf.all.send_redirects = 0
    sysctl --system

三、防火牆與 NAT (關鍵步驟)

# 1. 啟用 iptables 服務
systemctl enable --now iptables

# 2. NAT 出站 (假設外網卡為 eth0)
iptables -t nat -A POSTROUTING -o eth0 -s 10.8.0.0/24 -j MASQUERADE

# 3. 放行 PPTP 協議端口與 GRE
iptables -A INPUT -p tcp --dport 1723 -j ACCEPT
iptables -A INPUT -p gre -j ACCEPT

# 4. 允許 VPN 內部流量轉發
iptables -A FORWARD -i ppp+ -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o ppp+ -j ACCEPT
iptables -A FORWARD -i ppp+ -o ppp+ -j ACCEPT

# 5. 保存
service iptables save
# 或 iptables-save > /etc/sysconfig/iptables

四、啟動服務

systemctl enable --now pptpd
systemctl status pptpd

五、客戶端連接測試

  • Windows: 設定 → 網路和 Internet → VPN → 添加 VPN → 類型選 PPTP,填入公網 IP、用戶名、密碼。
  • Linux: nmcli con add type vpn vpn-type pptp ... 或圖形化網路管理器。
  • 手機: 設定 → VPN → 添加 PPTP。

六、常見問題排查

七、安全建議

  • 棄用 PPTP:協議已知漏洞 (MS-CHAPv2 可破解),生產環境強烈建議改用 L2TP/IPsec、IKEv2、WireGuard 或 OpenVPN。
  • 若必須用 PPTP:強制複雜密碼、限制來源 IP、啟用 MFA (Google Authenticator PAM)、審計日誌。
  • 定期更新 ppp/pptpd 套件修補 CVE。

總結

本教程提供了 CentOS 上 PPTP VPN 的最小可用部署流程。鑒於 PPTP 安全性不足,僅建議用於測試、舊設備相容或臨時應急場景。新建 VPN 基礎設施請優先選擇 WireGuard (高性能、現代加密) 或 IKEv2 (原生支援廣、穩定)。

Copyright © Windows教程網 All Rights Reserved
現象原因解決
619/800/807 錯誤GRE 協議被攔截 / 防火牆未放行 1723檢查 iptables GRE/TCP:1723;雲廠商安全組同步放行
連上但無法上網NAT 未生效 / 轉發鏈缺失 / DNS 未下發確認 ip_forward=1、MASQUERADE 規則、options.pptpd 中 ms-dns
頻繁斷線idle 超時 / MTU 過大 / ISP 干擾調大 idle、降低 MTU (1400)、嘗試 L2TP/IPsec 替代
多用戶衝突remoteip 池太小擴大 remoteip 範圍