Академический Документы
Профессиональный Документы
Культура Документы
Phoenix Follow
Jul 19, 2016 · 5 min read
概述
ipsec/l2tp VPN 协议由两个独立的协议组成:
环境要求
外网 IP 地址 1 个 CentOS 6 或 7 strongswan xl2tpd pppd
软件安装
安装 EPEL 源
具体请参考: https://fedoraproject.org/wiki/EPEL
安装 strongswan
安装 xl2tpd
安装 pppd
https://medium.com/@elvewyn/centos-6-%E4%B8%8B%E5%9F%BA%E4%BA%8E-strongswan-%E5%92%8C-xl2tpd-%E7%9A%84%E7%AE%… 1/6
2017/9/14 CentOS 6 下基于 strongswan 和 xl2tpd 的简易 VPN Server 安装配置
安装 pppd
pppd 会随 xl2tpd 一起安装。无需单独安装
apt -y install strongswan xl2tpd
软件配置工作
配置工作包含如下几项:
strongswan 配置
配置文件位于 /etc/strongswan
ipsec.conf
此文件是 strongswan 的主配置文件。配置示例如下:
conn vpnserver
type=transport
authby=secret
rekey=no
keyingtries=1
left=%any
leftfirewall=yes
right=%any
leftfirewall=yes
auto=add
ipsec.secrets
此文件中主要配置了 VPN 服务的 “预共享密钥”, 英文名称是
“Preshared Secret Key”
: PSK “1122334455”
其中 “1122334455” 请替换为实际中的预共享密钥。
启动 strongswan
https://medium.com/@elvewyn/centos-6-%E4%B8%8B%E5%9F%BA%E4%BA%8E-strongswan-%E5%92%8C-xl2tpd-%E7%9A%84%E7%AE%… 2/6
2017/9/14 CentOS 6 下基于 strongswan 和 xl2tpd 的简易 VPN Server 安装配置
通过如下命令启动:
/etc/init.d/strongswan start
防火墙配置
需要向互联网开放 UDP 协议的 500 和 4500
xl2tpd 配置
xl2tpd 负责实现具体的 VPN 交互。它的配置文件位于 /etc/xl2tpd 目
录中。 xl2tpd 自带了 DHCP 服务, 可以简化配置操作
xl2tpd.conf
[global]
port = 1701
access control = no
[lns default]
ip range = 10.17.3.2–10.17.3.255
local ip = 10.17.3.1
require authentication = yes
name = vpnserver
pppoptfile = /etc/ppp/options.xl2tpd
启动 xl2tpd
通过如下命令启动:
/etc/init.d/xl2tpd start
https://medium.com/@elvewyn/centos-6-%E4%B8%8B%E5%9F%BA%E4%BA%8E-strongswan-%E5%92%8C-xl2tpd-%E7%9A%84%E7%AE%… 3/6
2017/9/14 CentOS 6 下基于 strongswan 和 xl2tpd 的简易 VPN Server 安装配置
防火墙配置
需要开放 UDP 1701 端口。如果可以,建议只开放在 ipsec 协议保护下
的 1701 端口。
pppd 配置
pppd 由 xl2tpd 控制,完成具体的数据交换。其配置文件位于
/etc/ppp
options.xl2tpd
noccp
auth
crtscts
mtu 1410
mru 1410
#nodefaultroute
lock
proxyarp
silent
ms-dns 8.8.8.8
ms-dns 8.8.4.4
chap-secrets
此文件记录了登录 vpn 服务器用的用户名和密码
请根据需要来添加用户。每行对应一位用户。
启动 pppd
无需启动, pppd 将会由 xl2tpd 来负责启动。每个用户登录时,都会
启动一个对应的 pppd 进程
NAT 设置
https://medium.com/@elvewyn/centos-6-%E4%B8%8B%E5%9F%BA%E4%BA%8E-strongswan-%E5%92%8C-xl2tpd-%E7%9A%84%E7%AE%… 4/6
2017/9/14 CentOS 6 下基于 strongswan 和 xl2tpd 的简易 VPN Server 安装配置
NAT 设置
默认情况下, VPN 客户机将只能访问虚拟基于网内的资源。如果希望
访问外部网络资源,则需要配置相应的 NAT 规则。
https://medium.com/@elvewyn/centos-6-%E4%B8%8B%E5%9F%BA%E4%BA%8E-strongswan-%E5%92%8C-xl2tpd-%E7%9A%84%E7%AE%… 5/6
2017/9/14 CentOS 6 下基于 strongswan 和 xl2tpd 的简易 VPN Server 安装配置
https://medium.com/@elvewyn/centos-6-%E4%B8%8B%E5%9F%BA%E4%BA%8E-strongswan-%E5%92%8C-xl2tpd-%E7%9A%84%E7%AE%… 6/6