Secrets for authentication using CHAP

dfbn6 2026-05-27 VPN翻墙 16 0

CentOS 6.5 系统下搭建 IPsec/L2TP VPN 服务的完整指南(适合企业级部署)

在当前网络安全日益重要的背景下,远程访问内网资源的需求不断增长,对于仍在使用 CentOS 6.5 的老旧服务器环境(尽管该版本已于2024年停止维护),仍可通过配置 IPsec/L2TP 协议搭建稳定可靠的虚拟私人网络(VPN)服务,本文将详细介绍如何在 CentOS 6.5 上部署并优化这一组合方案,确保企业用户、远程办公人员或开发者能够安全、高效地接入内部网络。

确认系统环境:CentOS 6.5 默认已包含 kernel 2.6.32,支持 IPsec 和 L2TP 协议,需安装必要的软件包,包括 openswan(IPsec 实现)、xl2tpd(L2TP 守护进程)和 iptables(防火墙规则),执行命令如下:

yum install -y openswan xl2tpd iptables-services

接下来配置 IPsec,编辑 /etc/ipsec.conf 文件,定义主站点和客户端的通信策略:

config setup
    protostack=netkey
    plutodebug=all
    nat_traversal=yes
    interfaces=%defaultroute
conn L2TP-PSK-NAT
    right=%any
    left=YOUR_SERVER_IP
    leftid=@your-server.com
    rightsubnet=vhost:%priv
    auto=add
    authby=secret
    pfs=yes
    type=transport
    phase2alg=aes256-sha1
    modecfgdns="8.8.8.8 8.8.4.4"
    ikelifetime=8h
    keylife=1h
    rekey=no

然后配置预共享密钥(PSK),编辑 /etc/ipsec.secrets

YOUR_SERVER_IP %any : PSK "your_strong_pre_shared_key_here"

重启 IPsec 服务:

service ipsec restart
chkconfig ipsec on

接着配置 L2TP,编辑 /etc/xl2tpd/xl2tpd.conf

[global]
port = 1701
[lns default]
ip range = 192.168.100.100-192.168.100.200
local ip = 192.168.100.1
require chap = yes
refuse pap = yes
require authentication = yes
name = l2tpserver
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

创建 PPP 选项文件 /etc/ppp/options.xl2tpd

noauth
refuse-pap
refuse-chap
refuse-mschap
ms-dns 8.8.8.8
ms-dns 8.8.4.4
asyncmap 0
auth
crtscts
lock
modem
debug
name l2tpserver
proxyarp
lcp-echo-interval 30
lcp-echo-failure 4

添加用户账号到 /etc/ppp/chap-secrets


启动 L2TP 服务并设置开机自启:

service xl2tpd start
chkconfig xl2tpd on

关键步骤:启用 IP 转发和 NAT 规则,编辑 /etc/sysctl.conf 添加:

net.ipv4.ip_forward = 1

执行 sysctl -p 生效。

配置 iptables 放行流量:

iptables -A INPUT -p udp --dport 500 -j ACCEPT
iptables -A INPUT -p udp --dport 4500 -j ACCEPT
iptables -A INPUT -p udp --dport 1701 -j ACCEPT
iptables -A FORWARD -s 192.168.100.0/24 -d 192.168.0.0/24 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -j MASQUERADE
service iptables save

至此,CentOS 6.5 上的 IPsec/L2TP VPN 已部署完成,客户端可使用 Windows 或 iOS 自带的“连接到工作区”功能进行连接,输入服务器 IP、用户名密码即可建立加密隧道,此方案虽基于旧版系统,但稳定性强、兼容性好,特别适合遗留业务系统的远程访问场景,建议尽快升级至 CentOS Stream 或 AlmaLinux,以获得持续安全更新。

Secrets for authentication using CHAP

VPN加速器|半仙VPN加速器-免费VPN梯子首选半仙VPN