Ubuntu20.04 搭建L2TP+IPsec环境

1 安装

安装l2tp和strongswan。

sudo apt install xl2tpd

sudo apt install strongswan

2 ipsec配置

1)编辑**/etc/ipsec.conf**

shell 复制代码
conn L2TP-IPSEC
    authby=secret
    auto=add
    keyingtries=3
    ikelifetime=8h
    keylife=1h
    keyexchange=ikev2
    ike=chacha20poly1305-sha512-curve25519-prfsha512
    esp=chacha20poly1305-sha512,aes256gcm16-ecp384,aes256-sha256,aes256-sha1,3des-sha1
    # 连接类型 传输模式transport/隧道模式tunnel
    type=transport
    # 服务器公网地址
    left=10.25.X.X
    # 服务器子网网段
    leftsubnet=10.25.17.0/24[17/1701]
    # 客户端访问地址
    right=%any # right=10.25.16.0/24
    # rightsubnet=10.25.16.0/24[17/%any]
    dpddelay=30s
    dpdtimeout=150s
    dpdaction=clear

2)编辑**/etc/ipsec.secrets** , 设置ipsec的预共享秘钥

shell 复制代码
# This file holds shared secrets or RSA private keys for authentication.

# RSA private key for this host, authenticating it to any other host
# which knows the public part.
: PSK "123456"

3 l2tp配置

编辑**/etc/xl2tpd/xl2tpd.conf**

shell 复制代码
[global]
ipsec saref = no
debug tunnel = no
debug avp = no
debug network = no
debug state = no
access control = no
rand source = dev
port = 1701
auth file = /etc/ppp/chap-secrets

[lns default]
# 分配给客户端的私有网络地址
ip range = 192.168.100.100 - 192.168.100.254
# 服务器私有网络地址 绑定网卡的实际网络地址
local ip = 192.168.100.210
name = l2tp
pass peer = yes
refuse pap = yes
refuse chap = yes
require authentication = yes
ppp debug = no
# 指定PPP配置文件路径
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

4 ppp配置

1) 编辑PPP配置文件(例如上文中的**/etc/ppp/options.xl2tpd**)。

shell 复制代码
require-mschap-v2
refuse-mschap
# DNS服务器地址
ms-dns 127.0.0.53
asyncmap 0
auth
crtscts
idle 1800
mtu 1410
mru 1410
hide-password
local
modem
lock
name l2tpd
connect-delay 5000
lcp-echo-interval 30
lcp-echo-failure 4

2)编辑**/etc/ppp/chap-secrets**,添加VPN访问用户密码

shell 复制代码
# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
root * root *

5 重启服务

#重启服务

$sudo service xl2tpd restart

$sudo service ipsec restart

#确认服务状态

$sudo service xl2tpd status

$sudo service ipsec status

6 添加子网路由

当客户端可以连接到VPN服务器时,需要添加路由才可以访问私有网络中的其它机器。

shell 复制代码
# 添加访问192.168.100网段的路由
route add -net 192.168.100.0/24 netmask 255.255.255.0 gw 192.168.100.1
相关推荐
天远Date Lab5 小时前
零信任架构实战:基于天远租凭分期报告构建自动化汽车以租代购免押风控网关
网络·人工智能·架构·自动化
IT猿手7 小时前
实现NAPT、Easy-IP、NATserver、NATstatic
网络
迪康Defender7 小时前
终端供应链安全:应用白名单与软件正版化检测落地|终端安全治理实践
运维·服务器·网络·安全·web安全·自动化·运维开发
xiaoye-duck9 小时前
《C++ 项目:手写大模型接入 SDK》DeepSeek接口设计(下):流式响应实现和测试
开发语言·网络·c++·语言模型
其实防守也摸鱼10 小时前
信创安全竞赛知识总结与题库
大数据·网络·人工智能·算法·安全·php
万联WANFLOW10 小时前
异地厂区视频监控远程运维:从组网到安全的实施要点
运维·网络·安全·企业组网·sdwan
衍玊11 小时前
深入剖析 TCP/IP 网络通信原理与内核实现
服务器·网络·tcp/ip
.Bryce.11 小时前
从零到一开发技术名词大全:从需求分析到 AI Agent 工程
java·网络·人工智能·agent·需求分析·agent评测
Black蜡笔小新13 小时前
上云网关/端口穿透/设备上云EasyNTS:无需公网IP、也不改防火墙,设备怎么从内网跑到外网去
网络·网络协议·tcp/ip
Escalating_xu14 小时前
【Linux 网络编程】五种 I/O 模型与非阻塞 I/O:从“等数据”到正确处理 EAGAIN
java·linux·网络