在linux下搭建l2tp隧道


搭一個l2tp隧道,拓撲如下

兩台機器是CentOS5,內核選上CONFIG_LEGACY_PTYS選項后自己編譯的,l2tp是已經停更的l2tpd-0.69。先在LS上配置IP地址,iptables規則,這些不在多說,直接看l2tpd的配置文件

;/etc/l2tpd/l2tpd.conf
[global]
; if you run l2tpd on the internal interface only, enable the line below
; listen-addr = 192.168.1.98
[lns default]
ip range = 192.168.1.128- 192.168.1.254
local ip = 192.168.1.98
require chap = yes
refuse pap = yes
;下面這行說的是要PPP認證,我實際測試中感覺有沒有這一行都沒影響
require authentication = yes
ppp debug = yes
pppoptfile = /etc/ppp/options.l2tpd
length bit = yes

 然后是LS的pppd配置文件如下

#/etc/ppp/options.l2tpd
ipcp-accept-local
ipcp-accept-remote
ms-dns 192.168.1.1
ms-dns 192.168.1.3
ms-wins 192.168.1.1
ms-wins 192.168.1.3
noccp
#noauth
auth
crtscts
idle 1800
mtu 1200
mru 1200
# change line below to defaultroute to make all traffic go through the VPN
nodefaultroute
debug
lock
proxyarp
connect-delay 5000

再然后配置pppd的認證文件

#/etc/ppp/chap-secrets
"johnsnow"        *       "youknownothing"              192.168.1.0/24

 RS的l2tpd的配置文件如下

; Connect as a client to a server at 194.168.10.4
[lac myl2tp]
lns = 194.168.10.4
require chap = yes
refuse pap = yes
;require authentication = yes
; Name should be the same as the username in the PPP authentication!
ppp debug = yes
pppoptfile = /etc/ppp/options.l2tpd.client
length bit = yes

 RS的pppd配置文件如下

#/etc/ppp/options.l2tpd.client
ipcp-accept-local
ipcp-accept-remote
refuse-eap
noccp
#noauth
noauth
crtscts
idle 1800
mtu 1200
mru 1200
#nodefaultroute
defaultroute
debug
lock
#proxyarp
connect-delay 5000

RS的pppd認證文件

#/etc/ppp/chap-secrets
"johnsnow"        *       "youknownothing"

 分別在LS和RS上執行

l2tpd -c /etc/l2tpd/l2tpd.conf -D

 最后在RS上撥號

echo "c myl2tp" >/var/run/l2tp-control

 最后用ifconfig看一下,多了一個ppp接口說明撥號成功了。整個配置過程不難,但是我在配置LS的pppd配置文件時候走了一些彎路,在我配置了auth之后總是撥號不成功,最后在認證文件里最后一列加上了地址(192.168.1.0/24)才能認證成功。我猜想在LS的pppd啟動的時候RS的ppp0已經分到了一個192.168.1.0/24網段的地址,導致LS的pppd認證不通過,但是我不確定,非常不確定,有時間把代碼看一下。

這個配置僅僅使用了l2tp協議,並沒有使用ipsec相關協議,在網絡上還是明文傳輸的,如果要加密還需要配置ipsec。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM