发博文
正文 字体大小:

Ubuntu linux 连接 浙大VPN

(2007-01-05 14:10:40)
分类: Linux技术
设置环境:ubuntu6.04
 
步骤:
1. 安装相应软件 
# apt-get install ppp l2tpd
 
2. 编辑/etc/l2tpd/l2tpd.conf(这里的例子中有2个连接)
[global]                              ; Global parameters:
port = 1701                           ; * Bind to port 1701
 
[lac zju1]                            ; 连接名,可设置多个连接
name =
zealot@a                       ; VPN 的帐号名,别忘加@a/b/c/d
lns = lns.zju.edu.cn                  ; 学校的VPN服务器
refuse pap = yes                      ; * Refuse PAP authentication
require authentication = no           ;
ppp debug = yes                      打开debug
pppoptfile = /etc/l2tpd/zju.options  这个连接的配置文件名
 
[lac zju2]                            ; 连接名,可设置多个连接
name =
asci@a                         ; VPN 的帐号名,别忘加@a/b/c/d
lns = lns.zju.edu.cn                  ; 学校的VPN服务器
refuse pap = yes                      ; * Refuse PAP authentication
require authentication = no           ;
ppp debug = yes                      打开debug
pppoptfile = /etc/l2tpd/zju.options  这个连接的配置文件名
 
3. 编辑/etc/l2tpd/zju.options(l2tpd.conf中定义的配置文件):
asyncmap 0
noauth
crtscts
lock
hide-password
modem
netmask 255.255.255.0
proxyarp
lcp-echo-interval 30
lcp-echo-failure 4
ipcp-accept-local
ipcp-accept-remote
noipx

4. 编辑/etc/ppp/chap-secrets,为帐号设置密码
# Secrets for authentication using CHAP
# client        server            secret            IP addresses
 
asci@a       lns.zju.edu.cn     "password               *
 zealot@a      lns.zju.edu.cn     "password"                *

5. 连接脚本 /etc/l2tpd/vpninit.sh
#!/bin/bash
function connect
{
    COUNT=0
    echo "c zju1" > /var/run/l2tp-control  
                     ##把这里的 zju1 换为你想用的连接名
    while ! ifconfig | grep -s 'ppp0' > /dev/null; do
        sleep 2
        COUNT=`expr $COUNT + 2`
        echo "waited $COUNT seconds for ppp0 to come up."
        if [ $COUNT -gt 20 ]; then
            echo "*** ERROR ***"
            echo "Couldn't setup ppp0 properly after waited $COUNT seconds. exiting."
            break
        fi
    done
}
if [ $# = 1 ]; then
    if [ $1 = -r ]; then
        /etc/init.d/l2tpd restart
        # waiting for l2tpd to startup
        #while  ! test -f /var/run/l2tp-control ; do
            sleep 5
        #done
        connect
        ROUTE=$(ifconfig | grep P-t-P | awk '{print $3}' | cut -d':' -f2)
        ip route add default via $ROUTE dev ppp0
    fi
else
    if ! ifconfig | grep -s 'ppp0' > /dev/null; then
        connect
        IP=$(ip route | grep '^default' | cut -d" " -f3)
        ROUTE=$(ifconfig | grep P-t-P | awk '{print $3}' | cut -d':' -f2)
        ip route add 10.0.0.0/8 via $IP dev eth0
        ip route add 222.205.0.0/16 via $IP dev eth0
        ip route add 210.32.0.0/16 via $IP dev eth0
        ip route add 239.43.1.1/24 via $IP dev eth0
        ip route del default
        ip route add default via $ROUTE dev ppp0
    else
        echo 'already connected...'
    fi
fi
 
6. 连接实验:运行
# /etc/init.d/l2tpd start
# chmod +755 /etc/init.d/vpninit.sh
# /etc/init.d/vpninit.sh
再运行ifconfig,看有没有ppp0的interface,如果有就是成功了。
(如果成功则跳到第8步:启动设置和自动重连)
 
7. debug
先停止l2tpd工作,并打开一个前台的l2tpd工作台
# /etc/init.d/l2tpd stop
# l2tpd -D
这样,这个终端就被l2tpd占据
然后从另一个终端输入命令(假设要测试 连接 zju1):
# echo "c zju1" > /var/run/l2tp-control
然后看l2tpd终端的输出,特别是ppp的返回值,然后多man一下,一般能解决问题的。
 
8. 启动设置和自动重连设置(待以后更新)   
 
 
 
 
------------------
END
 

阅读 评论 收藏 转载 打印举报
  • 评论加载中,请稍候...

       

    验证码: 请点击后输入验证码 收听验证码

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 不良信息反馈 电话:4006900000 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有