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 VPS 搭建 IPSec + L2TP VPN 完整教程

編輯:Linux 教學

L2TP/IPSec 結合隧道協議與加密機制,安全性優於 PPTP。本文記錄基於 Openswan + xl2tpd 的源碼編譯安裝、雙層配置、內核參數調優、防火牆轉發及客戶端連接故障排查全過程。

第一階段:IPSec (Openswan) 部署

  1. 依賴安裝:yum install make gcc gmp-devel bison flex lsof
  2. 源碼編裝 Openswan 2.6.35:
    cd /tmp && wget https://www.openswan.org/download/openswan-2.6.35.tar.gz
    tar -zxvf openswan-2.6.35.tar.gz && cd openswan-2.6.35
    make programs install
  3. 核心配置 /etc/ipsec.conf:
    修改 protostack=netkey,添加 L2TP 連接定義(需替換 YOUR.SERVER.IP.ADDRESS 為 VPS 公網 IP)
  4. 預共享密鑰 /etc/ipsec.secrets:
    YOUR.SERVER.IP.ADDRESS %any: PSK "YourSharedSecret"
  5. 內核轉發優化:
    禁用 ICMP 重定向,啟用包轉發(net.ipv4.ip_forward=1),執行 sysctl -p 生效
  6. 驗證:ipsec verify 無 [FAILED] 即通過

第二階段:L2TP (xl2tpd + rp-l2tp) 部署

  1. 依賴:yum install libpcap-devel ppp policycoreutils
  2. 安裝 rp-l2tp 0.4(提取 l2tp-control):
    ./configure && make && cp handlers/l2tp-control /usr/local/sbin/
    mkdir /var/run/xl2tpd && ln -s /usr/local/sbin/l2tp-control /var/run/xl2tpd/l2tp-control
  3. 安裝 xl2tpd 1.3.0:make && make install
  4. 配置 /etc/xl2tpd/xl2tpd.conf:定義 IP 池(10.82.88.2-254)、本地網關、認證方式、PPP 選項文件路徑
  5. PPP 選項 /etc/ppp/options.xl2tpd:
    要求 MS-CHAPv2、指定 DNS(8.8.8.8/8.8.4.4)、啟用 proxyarp、LCP 保活
  6. 用戶認證 /etc/ppp/chap-secrets:格式 user l2tpd password *
  7. iptables NAT 轉發:
    iptables -t nat -A POSTROUTING -j MASQUERADE
    service iptables save && service iptables restart
  8. 除錯啟動:xl2tpd -D 確認監聽 UDP 1701

開機自啟動與 Windows 客戶端故障

  • 將內核參數、ipsec、xl2tpd 啟動命令寫入 /etc/rc.local
  • Windows 端報錯 768:需啟用系統服務 "IPsec Policy Agent" 及 "IKE and AuthIP IPsec Keying Modules"
Copyright © Windows教程網 All Rights Reserved