ubuntu创建VPN服务流程

1. 首先安装PPPD和xl2tpd:

sudo apt-get update
sudo apt-get install ppp xl2tpd

2. 安装strongswan程序 

l2tp是需要ipsec来进行加密的,又通常称为l2tp/ipsec,一般用strongswan来实现ipsec。检查系统安装了最新的strongswan程序,通过以下命令:

sudo apt install strongswan

3. 编辑/etc/ipsec.conf 

conn L2TP-IPSEC
    authby=secret
    auto=add
    keyingtries=3
    ikelifetime=8h
    keylife=1h
    ike=aes128-sha256-modp3072
    esp=aes128-sha256
    type=transport
    left=192.168.1.132
    leftsubnet=192.168.1.132[17/1701]
    right=192.168.100.0/24
    rightsubnet=192.168.100.0/24[17/%any]
    dpddelay=30s
    dpdtimeout=150s
    dpdaction=clear

这里left是表示Server端,即本机。leftsubnet=192.168.1.132[17/1701] 。这里 [ 前面是subnet,可以是单个地址,也可以是指定网络前缀的一个子网,[ ]的部分是protocol/port。根据自己的需求更改,protocol参考文件/etc/protocols中的定义

right表示client端,即远端。right可以用子网段来表示。rightsubnet中的%any表示任意地址,[]中为协议和端口,%any表示所有端口

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

# 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.
#the selector is optional
192.168.1.132 192.168.100.0/24 : PSK "secretkeys-for-vpn"

5. 创建文件/etc/ppp/options.xl2tpd

require-mschap-v2
refuse-mschap
ms-dns 8.8.8.8
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

l2tp是为PPP(point to point protocol)提供隧道服务的,所以ppp相关的配置也要设置。

5. 编辑/etc/xl2tpd/xl2tpd.conf

[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.1 - 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
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

lns表示L2TP network server,为vpn服务端。和它对应的另一端是lac,表示L2TP access concentrator,为vpn接入端

ip range是指lns在和lac建立连接后,将给其分配的地址区间。

local ip是指lns给本机分配的ip address

6. 编辑/etc/ppp/chap-secrets

# Secrets for authentication using CHAP
# client        server        secret                  IP addresses
  vpn1101         *          vpnpassword                   *

这里client是指客户端连接时的用户名user name。server栏是指本机名称,不指定可用*号表示。secret是客户端连接时用的密码。IP addresses是指客户端地址,不指定可用*号表示。

7. 启动xl2tpd服务并设置开机自启

sudo systemctl restart xl2tpd
sudo systemctl enable xl2tpd

sudo systemctl restart ipsec
sudo systemctl enable ipsec

8. 启用IP转发,确保所有流量都可以通过VPN:

sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

其中,eth0是外部网络接口的名称。

9 查看其运行状态

sudo service xl2tpd status

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值