linux 配置 l2tp-client

1,安装yum源

yum install epel-release

 

1,安装xl2tpd和ppp

yum -y install xl2tpd ppp

3.配置xl2tpd.conf,原始的xl2tpd.conf里面有[lns default],这个是将xl2tpd当做l2tpd服务器的关键语句。 要将xl2tpd作为l2tp的client端,需要把xl2tpd.conf里面的[lns default]部分删掉,加入[lac testvpn]部分。

[root@localhost ~]# vi /etc/xl2tpd/xl2tpd.conf

[global]

[lac testvpn]
name = test01                                                        ;L2TP的账号
lns = 1.1.1.1                                                            ;L2TP的服务器IP
pppoptfile = /etc/ppp/peers/testvpn.l2tpd            ;PPPD拨号时的配置文件
ppp debug = yes

4.设置拨号配置文件。

文件路径:xl2tpd.conf文件中pppoptfile =/etc/ppp/peers/testvpn.l2tpd

[root@localhost ~]# vi /etc/ppp/peers/testvpn.l2tpd  
remotename testvpn
user "test01"
password "Gn4JOfYXu"
unit 0
nodeflate
nobsdcomp
noauth
persist
nopcomp
noaccomp
maxfail 5
debug

5.配置文件都建好后,可以启动xl2tpd了(注意启动不代表拨号)。

systemctl start xl2tpd

6.开始拨号,连接VPN服务器。

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

拨号成功的话,通过ifconfig可以看见有个ppp0的接口

[root@localhost ~]# ifconfig ppp0
ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1492
        inet 172.16.4.43  netmask 255.255.255.255  destination 172.16.4.42
        ppp  txqueuelen 3  (Point-to-Point Protocol)
        RX packets 41  bytes 5451 (5.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 57  bytes 6541 (6.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

断开拨号命令:

echo 'd testvpn' > /var/run/xl2tpd/l2tp-control

7.l2tp连接上后,需要数据通过此ppp0接口出去的话,就需要配置路由了。

  yum install net-tools

route add -net 192.168.1.0 netmask 255.255.255.0 dev ppp0  # 这边的地址 是你需要访问的 内网段
posted @ 2019-07-22 16:07  滕虎  阅读(5532)  评论(0编辑  收藏  举报