yum install -y xl2tpd ppp
2.配置xl2tpd
vim /etc/xl2tpd/xl2tpd.conf
最下方追加下面代码
[lac gomez]
name = aomeng
lns = www.gomezddup.com
pppoptfile = /etc/ppp/peers/gomez.l2tpd
ppp debug = no
保存
说明:
gomez为连接名称,后面控制连接时需要
name为帐号的用名户,由服务器分配
lns为服务器ip地址
pppoptfile为连接选项
3。配置选项数据
vim /etc/ppp/peers/gomez.l2tpd
添加下面代码:
remotename gomez
user "aomeng"
password "123qwe"
unit 0
lock
debug
kdebug 1
mtu 1000
lcp-echo-interval 10
lcp-echo-failure 10
nobsdcomp
nodeflate
noaccomp
nopcomp
novj
defaultroute
保存
4.启动
执行下面俩个命令
service xl2tpd start
echo ‘c gomez‘ >/var/run/xl2tpd/l2tp-control
5.检查是否建立连接
执行命令
ifconfig
如果出现ppp0网卡即已经建立连接,否则就是出错了,检查/var/log/message日志排除问题
6.添加×××局域网路由
route add -net 172.172.0.0/16 dev ppp0
7.维护
连接:
service xl2tpd restart
echo ‘c gomez‘ >/var/run/xl2tpd/l2tp-control
断开PVN:
echo ‘d gomez‘ >/var/run/xl2tpd/l2tp-control
8.遇到的问题
每隔1.4 minutes就自动断开,/var/log/message日志如下
Jul 5 19:47:43 gomezddup xl2tpd[3511]: Maximum retries exceeded for tunnel 47411. Closing.
Jul 5 19:47:43 gomezddup xl2tpd[3511]: Connection 65153 closed to 192.168.21.123, port 1701 (Timeout)
Jul 5 19:47:43 gomezddup pppd[3513]: Terminating on signal 15
Jul 5 19:47:43 gomezddup pppd[3513]: Modem hangup
Jul 5 19:47:43 gomezddup pppd[3513]: Connect time 1.4 minutes.
Jul 5 19:47:43 gomezddup pppd[3513]: Sent 0 bytes, received 0 bytes.
Jul 5 19:47:43 gomezddup pppd[3513]: Connection terminated.
Jul 5 19:47:44 gomezddup pppd[3513]: Exit.
上面的问题笔者经过google、百度搜索了很多资料也未能解决,经过man pppd 仔细阅读,大胆的做出了猜测,xl2tpd连接×××服务器时,调用pppd来进行拨号,建立连接后,每隔几秒会向服务器发送echo-request请求,如果服务器因为某些原因(只能想到网络原因)未及时做出相应,pppd发送几次请求后就会自动中断链接。而/etc/ppp/peers/gomez.l2tpd中lcp-echo-interval lcp-echo-failure 这两项配置就是设置这个的。笔者根据网上查阅的资料,将其修改为0。重新拨号连接,还是会出现此问题。man pppd
lcp-echo-failure n
If this option is given, pppd will presume the peer to be dead if n LCP echo-requests are sent without receiving a valid LCP echo-reply. If this happens, pppd will terminate the connection. Use of
this option requires a non-zero value for the lcp-echo-interval parameter. This option can be used to enable pppd to terminate after the physical connection has been broken (e.g., the modem has
hung up) in situations where no hardware modem control lines are available.
英文不太好,但大概翻译了其中一句好像是此option的值应该是不为0。于是尝试将其改大一点。重新拨号,查看日志,几分钟后还是会断开。最后经过多次尝试修改,发现只有将lcp-echo-interval lcp-echo-failure这俩个的值都设置为10,就不会断线了,我到现在也没搞明白为什么?(如果谁知道,可以留言指教一下)
原文:http://blog.51cto.com/gengmin/2137040