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 5.5 搭建 L2TP/IPsec VPN 服務器完整教程

編輯:Linux 教學

架構規劃

  • 雙網卡閘道模式(單網卡旁路模式易產生路由異常,不推薦)
  • Eth0 (WAN):192.166.1.2/24 → 邊界防火牆 192.166.1.1
  • Eth1 (LAN):192.168.67.2/24 → 核心交換機 192.168.67.1
  • VPN 客戶端地址池:192.168.67.3-254

軟體版本

  • OS:CentOS 5.5
  • L2TP:xl2tpd 1.2.7(預設端口 1701/UDP)
  • IPsec:Openswan(需配合 xl2tpd 實現 L2TP/IPsec)

安裝 xl2tpd

yum install libpcap-devel ppp
wget https://www.xelerance.com/software/xl2tpd/xl2tpd-1.2.7.tar.gz
tar zxvf xl2tpd-1.2.7.tar.gz
cd xl2tpd-1.2.7
make && make install

核心配置文件

/etc/xl2tpd/xl2tpd.conf

[global]
listen-addr = 192.166.1.2
auth file = /etc/ppp/chap-secrets
debug tunnel = yes

[lns default]
ip range = 192.168.67.3-192.168.67.254
local ip = 192.168.67.2
require chap = yes
refuse pap = yes
require authentication = yes
name = xl2tpserver
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

/etc/ppp/options.xl2tpd

ipcp-accept-local
ipcp-accept-remote
ms-dns 8.8.8.8
ms-dns 221.7.17.21
noccp
auth
crtscts
idle 1800
mtu 1500
mru 1500
nodefaultroute
debug
lock
logfile /var/log/l2tpd.log
proxyarp
connect-delay 5000

/etc/ppp/chap-secrets

# client  server  secret  IP addresses
"test"  *  "test"  *

啟動腳本與服務註冊

# 建立 /etc/init.d/xl2tpd(內容見原文),賦予執行權限
chmod +x /etc/init.d/xl2tpd

# 修正二進制路徑差異
cp /usr/local/sbin/xl2tpd /usr/sbin/

# 加入服務管理
chkconfig --add xl2tpd
chkconfig xl2tpd on

# 啟動
service xl2tpd start

防火牆與 IPsec 配置提醒

  • 開放 UDP 500、4500、1701 端口
  • 配置 Openswan /etc/ipsec.conf 與 /etc/ipsec.secrets 實現 L2TP/IPsec 雙重加密
  • 啟用 IP 轉發:echo 1 > /proc/sys/net/ipv4/ip_forward 並寫入 /etc/sysctl.conf

測試驗證

Windows/iOS/Android 內建 VPN 客戶端新增 L2TP/IPsec 連線,輸入伺服器 IP、預共享金鑰、用戶名密碼即可撥號成功。

Copyright © Windows教程網 All Rights Reserved