在企业网络或远程办公场景中,通过安全的虚拟私人网络(VPN)连接访问内网资源是常见需求,CentOS 6.5作为一款经典的企业级Linux发行版,虽然已停止官方支持(EOL),但在一些遗留系统中仍被广泛使用,本文将详细介绍如何在CentOS 6.5环境下搭建IPsec + L2TP协议的VPN服务,帮助用户实现安全、稳定的远程接入。
确保系统已安装必要的软件包,执行以下命令更新系统并安装所需依赖:
yum update -y yum install -y xl2tpd ipsec-tools openswan
接下来配置IPsec,编辑 /etc/ipsec.conf 文件,添加如下内容:
config setup
plutostart=no
protostack=netkey
conn l2tp-psk
authby=secret
pfs=yes
type=transport
left=%defaultroute
leftprotoport=17/1701
right=%any
rightprotoport=17/1701
auto=add
然后配置共享密钥,编辑 /etc/ipsec.secrets:
%any %any : PSK "your_strong_pre_shared_key"
注意:请将 your_strong_pre_shared_key 替换为高强度密码(建议包含大小写字母、数字和特殊字符),避免使用弱口令。
完成IPsec配置后,配置L2TP服务器,编辑 /etc/xl2tpd/xl2tpd.conf:
[global]
listen-addr = 0.0.0.0
debug = yes
[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 = l2tp-server
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
创建PPP选项文件 /etc/ppp/options.xl2tpd:
noauth
ms-dns 8.8.8.8
ms-dns 8.8.4.4
proxyarp
lock
ncomp
设置用户认证信息,在 /etc/ppp/chap-secrets 中添加:
username * password *
john * mypassword * 表示用户名 john 密码 mypassword。
重启相关服务:
service ipsec start service xl2tpd start chkconfig ipsec on chkconfig xl2tpd on
开放防火墙端口(若启用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 service iptables save
常见问题排查:
- 若客户端无法连接,请检查IPsec日志:
tail -f /var/log/messages | grep pluto - L2TP连接失败时,查看xl2tpd日志:
tail -f /var/log/messages | grep xl2tpd - 确保NAT转发开启(如需公网IP):
echo 1 > /proc/sys/net/ipv4/ip_forward - 检查SELinux状态,临时关闭测试:
setenforce 0
通过以上步骤,即可在CentOS 6.5上成功部署IPsec/L2TP VPN服务,尽管该版本已不再受支持,但其稳定性和成熟度仍适合特定环境使用,建议后续逐步迁移至CentOS Stream或Red Hat Enterprise Linux等现代平台,以获得更好的安全更新和长期维护支持。

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

