在編譯成功源碼,安裝完畢xl2tpd後,便可以配置xl2tpd服務。基本配置過程主要涉及兩個配置文件:一個用來配置xl2tpd, 一個用來配置ppp協議。下面分別對這兩個文件進行說明,最後添加xl2tpd服務搭建過程。
具體信息也可以通過man來查看:
- man xl2tpd :啓動xl2tpd服務命令行傳遞參數說明
- man xl2tpd-control : 對xl2tpd進行參數配置的命令行說明
- man xl2tpd.conf :xl2tpd.conf配置文件配置信息說明
模塊說明:
xl2tpd | 用來提供L2TP協議服務 |
xl2tpd-control | 用來對xl2tpd進行參數配置:隧道、會話的增刪改查等 |
他們是兩個不同的進程,使用管道進行通信。
1. 使用GDB調試xl2tpd-control
如果需要使用GDB來輔助調試、學習xl2tpd, 需要在編譯階段加上-g選項,否則無法準確的跟蹤調試。直接打開源碼中的Makefile, 修改CFLAGS即可,之後重新編譯、安裝。Makefile修改信息如下:
如果需要單獨調試xl2tpd-control進程:掛載到GDB上後,傳遞參數可通過以下方式:
2. xl2tpd啓動參數說明
下面信息可以通過man xl2tpd進行查看
-D |
進入調試模式 |
-l |
記錄日誌信息 |
-c <config file> |
使用指定的配置文件,默認配置文件爲/etc/xl2tpd/xl2tpd.conf; 回退配置保留文件:/etc/xl2tpd/l2tpd.conf |
-s <secret file> |
認證的用戶信息,默認的文件爲/etc/xl2tpd/l2tp-secrets |
-p <pid file> |
使用指定的PID文件,默認/var/run/xl2tpd/l2tp-contol 這個文件用來進行管道通信使用的(控制交互),xl2tpd和xl2tpd-control之間進行進程間通信 |
-C |
同 -c |
3. xl2tpd.conf配置文件說明
下面信息可以通過man xl2tpd.conf進行查看
GLOBAL
SECTION
|
auth file |
用於對隧道的認證。默認文件爲: /etc/xl2tpd/xl2tpd.secrets |
ipsec asref |
用於ipsec的SA進行跟蹤。這是一個開關:yes or no |
|
saref refinfo |
|
|
listen-addr |
監聽的接口IP。默認爲0.0.0.0,即監控所有的接口 |
|
port |
監聽的端口,默認1701 |
|
access control |
訪問控制開關:yes or no 如果爲yes,只能允許指定的對端連接 |
|
debug avp |
|
|
debug network |
|
|
debug packet |
與-D配合使用,信息顯示在標準輸出上 |
|
debug state |
|
|
debug tunnel |
|
|
max retries |
隧道關閉前嘗試的次數,默認爲5 |
|
LNS SECTION |
exclusive |
只允許創建一個控制隧道 |
(no) ip range |
用於爲客戶端分配IP的IP地址池 |
|
assign ip |
是否分配IP。yes or no |
|
(no) lac |
指定lac的IP地址 |
|
hidden bit |
隱藏傳輸 |
|
local ip |
Xl2tpd本地IP |
|
local ip range |
爲客戶端分配的本地IP池,該項不受assign ip影響 |
|
length bit |
L2tp報文中length字段生效 |
|
(refuse|require) chap |
啓用或者禁用chap認證 |
|
(refuse|require) pap |
啓用和禁用pap認證 (yes or no) |
|
(refuse|require) authentication |
啓動和禁用認證 (yes or no)。對連接的用戶進行用戶和密碼認證 |
|
unix authentication |
If set yes, 將使用/etc/passwd 對對端ppp進行認證 |
|
hostname |
|
|
ppp debug |
|
|
pass peer |
|
|
pppoptfile |
ppp參數選項配置文件 |
|
call rws |
過時 |
|
tunnel rws |
隧道的窗口大小 |
|
flow bits |
啓用序號 |
|
challenge |
使用challenge向對端發起認證 |
|
rx bps |
接收帶寬 |
|
tx bps |
發送帶寬 |
|
LAC SECTION |
lns |
設置LNS地址信息 |
autodial |
如果設置爲yes,則在啓動時進行自動協商 |
|
redial |
重撥,set yes, 會話斷後會嘗試重撥 |
|
redial timeout |
設置重撥的超時時間 |
|
max redials |
設置重播次數 |
4. xl2tpd-control配置說明
下面信息可以通過man xl2tpd-control進行查看
xl2tpd-control [-c <PATH>] <command> <tunnel name> [<COMMAND OPTIONS>] |
||
Option |
-c |
用來指定xl2tpd配置文件 |
|
-d |
進入調試模式 |
COMMAND |
add |
添加新的或者修改已存的lac配置。 格式:<key>=<value> |
|
connect |
用來激活當前隧道 |
|
disconnect |
斷開當前隧道 |
|
remove |
刪除隧道 |
|
add-lac |
添加新的或者修改已存的lac配置 |
|
connect-lac |
|
|
disconnect-lac |
|
|
remove-lac |
|
|
add-lns |
添加新的或者修改已存的lns配置 |
|
remove-lns |
|
|
status |
|
|
status-lns |
|
|
available |
|
5. xl2tpd服務配置
首先要說明的是在xl2tpd源碼的examples目錄提供了最基本的配置實例,我們可以直接使用該配置,然後把其中的IP地址信息修改自己的虛擬機接口地址基本就可以完成。
root@book-virtual-machine:/usr/src/xl2tpd-1.3.15/examples# ls
chapsecrets.sample README xl2tpd-L2TP-CERT.conf xl2tpd-L2TP-PSK.conf
ppp-options.xl2tpd xl2tpd.conf xl2tpd-L2TP-CERT-orgWIN2KXP.conf xl2tpd-L2TP-PSK-orgWIN2KXP.conf
5.1 xl2tpd.conf服務配置
- 首先在/etc目錄下創建一個xl2tpd目錄,這個目錄是xl2tpd的默認路徑。
- 將源碼中examples目錄中的 xl2tpd.conf 拷貝到 /etc/xl2tpd/ 目錄。xl2tpd.conf的內容如下(分號是註釋),實際起作用的爲最後沒有註釋的那部分
;
; This is a minimal sample xl2tpd configuration file for use
; with L2TP over IPsec.
;
; The idea is to provide an L2TP daemon to which remote Windows L2TP/IPsec
; clients connect. In this example, the internal (protected) network
; is 192.168.1.0/24. A special IP range within this network is reserved
; for the remote clients: 192.168.1.128/25
; (i.e. 192.168.1.128 ... 192.168.1.254)
;
; The listen-addr parameter can be used if you want to bind the L2TP daemon
; to a specific IP address instead of to all interfaces. For instance,
; you could bind it to the interface of the internal LAN (e.g. 192.168.1.98
; in the example below). Yet another IP address (local ip, e.g. 192.168.1.99)
; will be used by xl2tpd as its address on pppX interfaces.
[global]
; listen-addr = 192.168.1.98
;
; requires openswan-2.5.18 or higher - Also does not yet work in combination
; with kernel mode l2tp as present in linux 2.6.23+
; ipsec saref = yes
; Use refinfo of 22 if using an SAref kernel patch based on openswan 2.6.35 or
; when using any of the SAref kernel patches for kernels up to 2.6.35.
; saref refinfo = 30
;
; force userspace = yes
;
; debug tunnel = yes
[lns default]
ip range = 192.168.1.128-192.168.1.254
local ip = 192.168.1.99
require chap = yes
refuse pap = yes
require authentication = yes ;這是註釋: 如果不需要認證,把yes改爲no即可
name = LinuxVPNserver
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd ;這是註釋:PPP協議參數配置
length bit = yes
5.2 PPP參數選項配置
PPP參數選項文件是通過上述的xl2tpd.conf中指定的:pppoptfile = /etc/ppp/options.xl2tpd
- 這個目錄好像不需要自己創建(我自己沒有創建,可能是安裝時自動創建的,也可能是百問網虛擬機已經安裝了PPP)
- 將源碼中examples目錄中的 ppp-options.xl2tpd 拷貝到 /etc/ppp/ 目錄下,並改名爲options.xl2tpd(要與剛指定文件名一致)。內容如下:
ipcp-accept-local
ipcp-accept-remote
ms-dns 192.168.1.1
ms-dns 192.168.1.3
ms-wins 192.168.1.2
ms-wins 192.168.1.4
noccp
idle 1800
mtu 1410
mru 1410
nodefaultroute
debug
lock
proxyarp
connect-delay 5000
5.3 用戶名和密碼預置
用戶名和密碼是需要提前預置的,否則在開啓認證功能是無法創建隧道。
預置用戶名和密碼的文件也只可以手動指定的。 它在源碼的examples目錄也有提供: chapsecrets.sample可以拿來直接使用。我嘗試了好幾次,發現在啓動xl2tpd進程時通過-c選項來制定認證文件發現依然提示上述錯誤(抓包發現是PPP在chap認證時失敗導致的),後來把/etc/ppp/chap-secrets文件添加上自己預置的用戶和密碼發現可以連接成功,也不需要指定該文件,應該是默認的文件,暫不清楚原因。文件內容如下:
root@book-virtual-machine:/etc/ppp# cat chap-secrets
# Secrets for authentication on server using CHAP
# client server secret IP addresses
jacco * "mysecret" 192.168.1.128/25 # Dynamic IP
sam * "rumpelstiltskin" 192.168.1.5 # Static IP
sunzd * "123456" 192.168.1.100 #這是我自己添加的
#
# Secrets for authentication on client using CHAP
# client server secret IP addresses
* jacco "mysecret"
* sam "rumpelstiltskin"
* sunzd "123456" #這是我自己添加的
5.4 啓動xl2tpd服務
直接運行xl2tpd便可以,如果需要查看調試信息,加上-D選項即可。
這裏可能提示/var/run ...錯誤,這裏需要創建一個目錄xl2tpd,用途是:xl2tpd和xl2tpd-control會在該目錄下創建一個管道用來通信。