Linux 使用 xl2tpd 建立 L2TP 隧道(WITHOUT IPSEC)

Linux 使用 xl2tpd 建立 L2TP 隧道(WITHOUT IPSEC)

准备环境 ppp、x2ltpd (服务器端和客户端均需要安装)

1、服务器端配置

1.1、在 xl2tpd.conf 文件中配置 pppoptfile

centos 7安装环境:

yum install epel-release -y
yum install xl2tpd -y

vi /etc/xl2tpd/xl2tpd.conf

[lns default]
ip range = 192.168.0.2-192.168.0.20
local ip = 192.168.0.1
require chap = yes
refuse pap = yes
name = vpn_company
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

1.2、设置安全认证

vi /etc/ppp/options.xl2tpd

noccp
noauth
idle 1800
mtu 1410
mru 1410
nodefaultroute
connect-delay 5000

1.3、配置 L2TP 用户认证

vi /etc/ppp/chap-secrets

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

/etc/init.d/xl2tpd restart

1.4、配置转发(连通外网eth1)

echo "net.ipv4.ip_forward = 1" > /etc/sysctl.conf

sysctl -p
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE   //(centos6)
firewall-cmd --permanent --direct --passthrough ipv4 -t nat -I POSTROUTING -o eth1 -j MASQUERADE -s 192.168.0.0/24
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p gre -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv6 filter INPUT 0 -p gre -j ACCEPT
firewall-cmd --permanent --add-masquerade
firewall-cmd --reload

2、客户端配置

2.1、配置客户端认证信息

vi /etc/ppp/peers/vpn_company

remotename vpn_company
user "test"
password "test"
ipcp-accept-local
ipcp-accept-remote
refuse-eap
require-mschap-v2
noccp
noauth
noipdefault
mtu 1410
mru 1410
usepeerdns
debug
connect-delay 5000

2.2、配置 lac

vi /etc/xl2tpd/xl2tpd.conf

[lac vpn_company]
lns = 192.168.159.132
pppoptfile = /etc/ppp/peers/vpn_company
ppp debug = yes

lns 为远程 VPN 服务器地址。

/etc/init.d/xl2tpd restart

3、在客户端建立 L2TP 连接

连接到指定 lac

echo 'c vpn_company' > /var/run/xl2tpd/l2tp-control

vpn_conf 为 /etc/xl2tpd/xl2tpd.conf 中配置的 lac 名称

成功建立连接后,可以看到如下 ppp 网卡信息。

ppp0      Link encap:点对点协议  
          inet 地址:192.168.0.2  点对点:192.168.0.1  掩码:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1410  跃点数:1
          接收数据包:4 错误:0 丢弃:0 过载:0 帧数:0
          发送数据包:4 错误:0 丢弃:0 过载:0 载波:0
          碰撞:0 发送队列长度:3 
          接收字节:58 (58.0 B)  发送字节:76 (76.0 B)

关闭 L2TP 连接

echo "d vpn_company" > /var/run/xl2tpd/l2tp-control
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇