搞定ubuntu下L2TP VPN的连接

包含网卡/无线网的网络问题和ADSL/校园网/宽带拨号支持及代理/共享等网络使用问题
躺在桌子上
帖子: 405
注册时间: 2008-10-27 22:28

搞定ubuntu下L2TP VPN的连接

#1

帖子 躺在桌子上 » 2008-11-05 11:54

搞定ubuntu下L2TP VPN的连接

网上关于LINUX下的L2TP VPN客户端连接的说明不是太多,而我由于工作需要,必须连接L2TP的VPN,所以在朋友的帮助下终于搞定了他,虽然目前在WINE下还没有连接成功我的ERP,但是我还是把我连接的过程贡献出来,这样才比较符合LINUX的精神。

我的参考:
ttp://www.cublog.cn/u/8057/showart_83292.html
http://www.linuxsir.org/bbs/thread288764.html
还有其他的网页,但是由于没有记录,在此一并表示感谢。

我写的这个主要是对他们的配置的一个进一步注解,适合和我一样的菜鸟。

本来我一直以为L2TPD和XL2TPD是两个东西,但是我发现,我删除了XL2TPD,安装L2TPD后,依然可以启动XL2TPD。

安装好L2PTD以后,首先要更改配置。

#下面引用:http://www.cublog.cn/u/8057/showart_83292.html (#)号后是我的注解

完了修改这样几个东西:
/etc/l2tpd/l2tpd.conf
添加一个lac section,比如:
[lac seubras] #其中SEUBRAS是你自己决定的,你可以自己设定,以后会用到,我设置的是chengji
lns = bras.seu.edu.cn #lns 后面填写你的VPN服务器地址
redial = yes
redial timeout = 15
max redials = 5
require chap = yes
refuse pap = yes
require authentication = yes
name = hellwolf@a #你的用户名,比如我的是name = chengji
ppp debug = no
pppoptfile = /etc/ppp/options.l2tpd
其中这个lac配置的名称叫seubras,其中name就是用户名,lns是服务器的地址,ppp选项为文件/etc/ppp /options.l2tpd中,同时使用的是chap协议认证,那么如果你熟悉ppp那么就应该知道,为了指定密码你需要修改,/etc/ppp /chap-secrets文件,格式为:
# client server secret IP addresses
通常这样就可以了
hellwolf@a * mypassword * #注意*号不要漏了,我的是 chengji * 密码 *
关于ppp的选项,通常不需要对服务器进行验证,所有记得加一个noauth选项并去掉可能存在的auth选项,proxyarp选项是一定要打开的,而且一般来说defaultroute也是你需要的,所以我的ppp选项是这样的:
noauth
proxyarp
defaultroute

#下面引用:http://hi.baidu.com/kaoik/blog/item/93a ... bf764.html
/etc/ppp/chap-secrets
同上,这个是使用chap协议认证时所用的用户名和密码,保险起见,两个认证方式我们都加上用户名和密码。
引用内容:
username * password *

#引用结束

接下来按照 的叙述,应该要
#下面引用:http://hi.baidu.com/kaoik/blog/item/93a ... bf764.html

3. 配置拨号脚本
在配置完xl2tpd之后,还需要写一个拨号脚本,来控制xl2tpd进行VPN拨号。
将以下脚本存为/usr/local/sbin/bras-ctrl,可以使用命令sudo gedit /usr/local/sbin/bras-ctrl来创建。
如果直接复制过去保存后运行出现错误的话,那就可能因为换行符的问题,你需要自己把这些输入进去了。
注意:脚本中GATEWAY对应网关,route命令中的路由添加需要根据自己的网络环境来设置,还有拨号服务器的地址也要修改。
程序代码:[ 复制代码到剪贴板 ]
#!/bin/sh
case $1 in
route)
GATEWAY=10.9.232.1
{
route $2 -net 220.189.211.160 netmask 255.255.255.224 gw $GATEWAY
route $2 -net 218.108.82.160 netmask 255.255.255.240 gw $GATEWAY
route $2 -net 10.0.0.0 netmask 255.0.0.0 gw $GATEWAY
route $2 -net 172.16.0.0 netmask 255.240.0.0 gw $GATEWAY
route $2 -net 192.168.0.0 netmask 255.255.0.0 gw $GATEWAY
route $2 -net 210.32.24.0 netmask 255.255.252.0 gw $GATEWAY
route del default
if [ "$2"=="add" ]
then
# 此处host为拨号服务器地址
route add -host 61.130.10.217 eth0
fi
if [ "$2"=="del" ]
then
route add -net default gw $GATEWAY
fi
}&>/dev/null
modprobe ip_nat_ftp
;;
start)
mkdir /var/run/xl2tpd
echo '''' > /var/run/xl2tpd/l2tp-control
xl2tpd
sleep 5
echo ''c zstubras'' > /var/run/xl2tpd/l2tp-control
;;
stop)
echo ''d zstubras'' > /var/run/xl2tpd/l2tp-control
;;
*)
echo ''Please specify your action: route add/del | start | stop''
;;
esac

#引用结束

这是跟路由相关的,根据你自己网络状况的不同,需要更改一下,我是在公司的内网。但是我先没有管他,只改了下# 此处host为拨号服务器地址
route add -host 61.130.10.217 eth0

然后我先拿ROOT, sudo -i

接着 echo ''c chengji'' > /var/run/xl2tpd/l2tp-control #chengji就是[lac seubras] 中我填写的内容[lac chengji]

ifconfig -a 查看,出现一个网卡
ppp0 Link encap:Point-to-Point Protocol
inet addr:172.16.1.30 P-t-P:123.132.123.123 Mask:255.255.255.255 #123.132.123.123是我的VPN服务器IP,我改了。
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:5 errors:0 dropped:0 overruns:0 frame:0
TX packets:6575960 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:98 (98.0 B) TX bytes:2465197527 (2.2 GB)

说明已经拨上去了,但现在是PING不通的,然后开始配置路由。

可以先ip route show 看一下

接着 ip route add 172.16.1.0/24 via 172.16.1.30 dev ppp0

然后ip route show 就可以看到你的VPN服务器IP和分配给你的VPN内网IP的一个连接了。

这样应该就可以PING通了

#似乎不太稳定,刚开始PING不同,而且老是断线重拨,IP地址被重新分配,第二天才搞定,不清楚是什么原因,突然一下就PING通了,并且PING通之后就很稳定了,没有断过。

上面的一个拨号配置,我自己搞的时候就看不懂,不知道上面的ROUTE应该怎么修改,现在的经验就是不管他,等拨上了在命令行中添加就是了。

另外,如果每次都是通过命令行来启动,并且要手动添加一下路由,这对我们这些菜鸟来说真是比较痛苦的事情。

由于我也是菜鸟,也是靠别人的帮助才搞定的,所以上面的描述有不对的地方,请大家指正。
guocai
帖子: 4
注册时间: 2009-04-23 11:21

Re: 搞定ubuntu下L2TP VPN的连接

#2

帖子 guocai » 2009-04-23 11:31

楼主你好 我学校用的也是锐捷和l2tp 我按照你的方法做 还是失败了
有几点我不是很明白 你能解释下吗?

l2tpd.conf中的用户名 我的是gzVPDN9957545@qgxy.v.gd 我是不是应该这样name = gzVPDN9957545@qgxy.v.gd 还是name = gzVPDN9957545@a?还是其他写法?

bras-ctrl文件中GATEWAY=10.9.232.1这个是自己内网的网关吗?还是VPN服务器的网关? {}中的数据来源是哪?我在XP下查看客户端 只看到一组数据:静态路由表:172.16.0.0 mask:255.252.0.0


我想我出错的关键就在这几个点上 麻烦你帮帮我。
loby
帖子: 3
注册时间: 2008-10-28 13:41

Re: 搞定ubuntu下L2TP VPN的连接

#3

帖子 loby » 2009-04-25 0:10

我都试过很多次了,都不行阿。楼上的是广轻的把 :em01 :em01 :em01
exia
帖子: 2
注册时间: 2009-04-26 17:25

Re: 搞定ubuntu下L2TP VPN的连接

#4

帖子 exia » 2009-04-26 17:29

广轻那位同学如果搞定了,分享一下啊.校友哦
guocai
帖子: 4
注册时间: 2009-04-23 11:21

Re: 搞定ubuntu下L2TP VPN的连接

#5

帖子 guocai » 2009-04-26 19:30

不错,够细心,懂得看帐号
这个配置我已经搞定了 文档也写好了 放在ftp://172.17.92.165
轻院linux爱好者群: 1016776
我的邮箱:guocai@live.com

有什么疑问可以找我
303969307
帖子: 3
注册时间: 2009-02-05 23:31

Re: 搞定ubuntu下L2TP VPN的连接

#6

帖子 303969307 » 2009-04-27 10:54

guocai, 校友啊 财哥!!@@!
loby
帖子: 3
注册时间: 2008-10-28 13:41

Re: 搞定ubuntu下L2TP VPN的连接

#7

帖子 loby » 2009-04-27 16:20

非常感谢咯 :em01 :em01
exia
帖子: 2
注册时间: 2009-04-26 17:25

Re: 搞定ubuntu下L2TP VPN的连接

#8

帖子 exia » 2009-05-03 12:52

万分感谢!立刻试验一下.
kongqilin
帖子: 4
注册时间: 2009-04-29 12:51

ubuntu9.10下L2TP +锐捷上网

#9

帖子 kongqilin » 2009-05-12 16:29

参考:
http://www.cublog.cn/u/8057/showart_83292.html
http://www.linuxsir.org/bbs/thread288764.html

一.基本设置
1。在新立得软件管理器先卸载掉Network Manager


2。打开终端,输入 sudo gedit /etc/network/interfaces

auto lo
iface lo inet loopback #这2行 本来就有 , 添加下面的代码
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 59.72.65.12 #换成自己的IP地址
netmask 255.255.255.0 #换成自己的子网掩码
gateway 59.72.65.254 #换成自己的网关

保存 退出


3。终端 输入 sudo gedit /etc/resolv.conf
# Generated by NetworkManager #这一行 本来就有 ,添加下面的代码
nameserver 202.198.16.3 #换成自己 DNS
nameserver 202.106.0.20 #换成自己 DNS

保存退出


4。永久更改mac 如果 mac 和自己网卡的一致 此步省略
终端输入 sudo gedit /etc/init.d/rc.local

在PATH=/sbin:/bin:/usr/sbin:/usr/bin上面插入以下内容
代码:

/sbin/ifconfig eth0 down
/sbin/ifconfig eth0 hw ether 00:00:00:00:00:00 #mac 换成你自己的网卡地址
/sbin/ifconfig eht0 up
/etc/init.d/networking restart

保存退出


二、配置锐捷验证


1.在网上下载myxrgsu

把myxrgsu.tar.gz文件拷贝到你的主目录里,然后如下:
administrator@administrator-desktop:~$ tar -zxvf myxrgsu.tar.gz #解压缩myxrgsu.tar.gz文件
administrator@administrator-desktop:~$ cd myxrgsu/ #进入myxrgsu目录中
administrator@administrator-desktop:~$ sudo cp libpcap.so.0.6.2 /usr/lib #拷贝库文件
administrator@administrator-desktop:~$ sudo cp libstdc++.so.5 /usr/lib #拷贝库文件
administrator@administrator-desktop:~$ sudo cp myxrgsu /usr/bin #拷贝库文件
administrator@administrator-desktop:~$ sudo myxrgsu
[sudo] password for administrator:
XRGSupplicant 1.1.1
Ruijie Network CopyRight 2004-2005
Please input your user name:2007060503302 #输入你的锐捷帐号
Please input your password: #输入你的锐捷密码
Use DHCP,1-Use,0-UnUse(Default: 0):
Use default auth parameter,0-Use 1-UnUse(Default: 0):
Searching server...
Connecting server...
Authenticating...
Authenticate SUCCESSFULLY!
Please input 'unauth' to LogOff:

重启。
三、配置l2tp验证



1、安装xl2tp

可以从http://packages.ubuntu.com/zh-cn/intrep ... d/download下载,双击下载好的xl2tpd_1.2.0+dfsg-1ubuntu1_i386.deb进行安装

2.在/etc/xl2tpd/xl2tpd.conf末尾添加一个lac段(如下)。

administrator@administrator-desktop:~$ sudo gedit /etc/xl2tpd/xl2tpd.conf

[lac gdqy]
lns = 192.168.129.1 #192.168.129.1是VPN拨号服务器
redial = yes
redial timeout = 15
max redials = 5
require pap = yes
require chap = yes
require authentication = yes
name = 0000000000@qgxy.v.gd #将name = 0000000000@qgxy.v.gd 改成你的宽带帐号
ppp debug = no
pppoptfile = /etc/ppp/options.l2tpd

3.编辑/etc/ppp/chap-secrets
administrator@administrator-desktop:~$ sudo gedit /etc/ppp/chap-secrets


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

0000000000@qgxy.v.gd * 000000 * #将文件中的0000000000@qgxy.v.gd改成你的宽带帐号,000000改成密码


4.编辑/etc/ppp/pap-secrets
administrator@administrator-desktop:~$ sudo gedit /etc/ppp/pap-secrets #作修改同chap-secrets



# /etc/ppp/pap-secrets
#
# This is a pap-secrets file to be used with the AUTO_PPP function of
# mgetty. mgetty-0.99 is preconfigured to startup pppd with the login option
# which will cause pppd to consult /etc/passwd (and /etc/shadow in turn)
# after a user has passed this file. Don't be disturbed therefore by the fact
# that this file defines logins with any password for users. /etc/passwd
# (again, /etc/shadow, too) will catch passwd mismatches.
#
# This file should block ALL users that should not be able to do AUTO_PPP.
# AUTO_PPP bypasses the usual login program so it's necessary to list all
# system userids with regular passwords here.
#
# ATTENTION: The definitions here can allow users to login without a
# password if you don't use the login option of pppd! The mgetty Debian
# package already provides this option; make sure you don't change that.

# INBOUND connections

# Every regular user can use PPP and has to use passwords from /etc/passwd

* hostname "" *

# UserIDs that cannot use PPP at all. Check your /etc/passwd and add any
# other accounts that should not be able to use pppd!

guest hostname "*" -
master hostname "*" -
root hostname "*" -
support hostname "*" -
stats hostname "*" -

# OUTBOUND connections

# Here you should add your userid password to connect to your providers via
# PAP. The * means that the password is to be used for ANY host you connect
# to. Thus you do not have to worry about the foreign machine name. Just
# replace password with your password.
# If you have different providers with different passwords then you better
# remove the following line.

# * password

0000000000@qgxy.v.gd * 000000 * #将文件中的0000000000@qgxy.v.gd改成你的宽带帐号,000000改成密码


5.编辑/etc/ppp/options.l2tpd
administrator@administrator-desktop:~$ sudo gedit /etc/ppp/options.l2tpd #内容如下

noauth
proxyarp
defaultroute

保存退出
6。编辑/usr/local/sbin/bras-ctrl
administrator@administrator-desktop:~$ sudo gedit /usr/local/sbin/bras-ctrl


#!/bin/sh
## For xl2tpd: /etc/init.d/xl2tpd
## For l2tpd: /etc/init.d/l2tpd

L2TPD_SCRIPT=/etc/init.d/xl2tpd
## For xl2tpd: /var/run/xl2tpd/l2tp-control
## For l2tpd: /var/run/l2tp-control

L2TPD_PIPE=/var/run/xl2tpd/l2tp-control
case $1 in
route)
GATEWAY=172.17.92.254 #将GATEWAY=172.17.1.254 改成你的静态IP的默认网关
{
route $2 -net 220.189.211.160 netmask 255.255.255.224 gw $GATEWAY
route $2 -net 218.108.82.160 netmask 255.255.255.240 gw $GATEWAY
route $2 -net 10.0.0.0 netmask 255.0.0.0 gw $GATEWAY
route $2 -net 172.16.0.0 netmask 255.240.0.0 gw $GATEWAY
route $2 -net 192.168.0.0 netmask 255.255.0.0 gw $GATEWAY
route $2 -net 210.32.24.0 netmask 255.255.252.0 gw $GATEWAY
route del default
if [ "$2"=="add" ]
then
route add -host 192.168.129.1 eth0 # 此处host为拨号服务器地址
fi
if [ "$2"=="del" ]
then
route add -net default gw $GATEWAY
fi
}&>/dev/null
modprobe ip_nat_ftp
;;
start)
echo "" > /var/run/xl2tpd/l2tp-control
xl2tpd
sleep 5
echo "c gdqy" > /var/run/xl2tpd/l2tp-control
;;
stop)
echo "d gdqy" > /var/run/xl2tpd/l2tp-control
;;
*)
echo "Please specify your action: route add/del | start | stop"
;;
esac

administrator@administrator-desktop:~$ sudo chmod 777 /usr/local/sbin/bras-ctrl



保存退出。 到此,l2tp配置完成!重启电脑。

四.联网
1。锐捷认证
administrator@administrator-desktop:~$ sudo myxrgsu
[sudo] password for administrator:
XRGSupplicant 1.1.1
Ruijie Network CopyRight 2004-2005
Please input your user name:2007060504408 #输入你的锐捷帐号
Please input your password: #输入你的锐捷密码
Use DHCP,1-Use,0-UnUse(Default: 0):
Use default auth parameter,0-Use 1-UnUse(Default: 0):
Searching server...
Connecting server...
Authenticating...
Authenticate SUCCESSFULLY!
Please input 'unauth' to LogOff:

2。l2tp认证

以下以广东轻院L2TP配置导入进行说明

LNSIP=192.168.129.1
2
172.16.0.0 mask 255.252.0.0;#路由器
211.66.184.0 mask 255.255.248.0;#路由器

打开新的终端
administrator@administrator-desktop:~$ sudo route -n
[sudo] password for administrator:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.17.92.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
0.0.0.0 172.17.92.254 0.0.0.0 UG 100 0 0 eth0

administrator@administrator-desktop:~$ sudo route add -net 172.16.0.0 netmask 255.252.0.0 gw 172.17.92.254 #将172.17.1.254 改成你的静态IP的默认网关
administrator@administrator-desktop:~$ sudo route add -net 211.66.184.0 netmask 255.255.248.0 gw 172.17.92.254
administrator@administrator-desktop:~$ sudo route add -net 192.168.129.1 netmask 255.255.255.255 gw 172.17.92.254
administrator@administrator-desktop:~$ sudo -i bras-ctrl start
administrator@administrator-desktop:~$ route -n

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.129.1 172.17.92.254 255.255.255.255 UGH 0 0 0 eth0
113.66.126.1 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0 #113.66.126.1
172.17.92.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
211.66.184.0 172.17.92.254 255.255.248.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
172.16.0.0 172.17.92.254 255.252.0.0 UG 0 0 0 eth0
0.0.0.0 172.17.92.254 0.0.0.0 UG 100 0 0 eth0

administrator@administrator-desktop:~$ sudo route add -net 0.0.0.0 netmask 0.0.0.0 gw 113.66.126.1#动态添加路由(注意:113.66.126.1)要跟上面相对应
administrator@administrator-desktop:~$route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.129.1 172.17.92.254 255.255.255.255 UGH 0 0 0 eth0
113.66.124.1 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
172.17.92.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
211.66.184.0 172.17.92.254 255.255.248.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
172.16.0.0 172.17.92.254 255.252.0.0 UG 0 0 0 eth0
0.0.0.0 113.66.126.1 0.0.0.0 UG 0 0 0 ppp0

上次由 kongqilin 在 2009-05-30 16:10,总共编辑 14 次。
guocai
帖子: 4
注册时间: 2009-04-23 11:21

Re: 搞定ubuntu下L2TP VPN的连接

#10

帖子 guocai » 2009-05-13 21:38

那个是我写的配置 不过其中很多问题
kingdom2250
帖子: 2
注册时间: 2008-03-13 19:14

Re: 搞定ubuntu下L2TP VPN的连接

#11

帖子 kingdom2250 » 2009-05-29 2:03

在这个Ubuntu论坛里就见到我们广轻院的那么多朋友····,非常感谢各位朋友的分享
mywei1989
帖子: 56
注册时间: 2008-10-26 19:39

Re: 搞定ubuntu下L2TP VPN的连接

#12

帖子 mywei1989 » 2009-08-30 18:50

错误一大堆
:em04
头像
oyasmi
帖子: 173
注册时间: 2007-06-04 9:54
来自: 南京

Re: 搞定ubuntu下L2TP VPN的连接

#13

帖子 oyasmi » 2009-08-30 20:03

呵呵,也是seu的呀!
等待青春散场;等待年华老去!
mywei1989
帖子: 56
注册时间: 2008-10-26 19:39

Re: 搞定ubuntu下L2TP VPN的连接

#14

帖子 mywei1989 » 2009-08-31 10:21

最后替换路由那步过不了··· :em20
mywei1989
帖子: 56
注册时间: 2008-10-26 19:39

Re: 搞定ubuntu下L2TP VPN的连接

#15

帖子 mywei1989 » 2009-08-31 12:29

问下
静态IP DNS为:
10.1.23.52
255.255.255.0
10.1.23.253

172.16.3.3
172.16.3.4

L2TP导入配置文件为:
LNSIP=10.10.8.254
3
172.26.0.0 mask 255.255.0.0;
172.16.0.0 mask 255.255.0.0;
10.1.0.0 mask 255.255.0.0;


bras-ctrl 文件应该怎么写?
回复