Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> Linux系統教程 >> Linux教程 >> 如何利用centOS5.5搭建l2tpd vpn服務器

如何利用centOS5.5搭建l2tpd vpn服務器

日期:2017/2/7 14:37:10      編輯:Linux教程
 

服務器要求:雙網卡,作網關。如果用單網卡服務器,作旁路方式,也可以拔通和訪問資源,但在實際應用中會中會有莫名其妙的網絡數據傳輸出錯的問題,不建議使用。
網絡參照如下圖:
路由器----防火牆-----l2tp服務器-------核心交換機
l2tp服務器接口和地址:Eth0 192.166.1.2 --- l2tp服務器--- Eth1 192.168.67.2
服務器網絡地址規劃:
Eth0 192.166.1.2 mask 255.255.255.0 接入邊界防火牆,邊界防火牆接口設為192.166.1.1 mask 255.255.255.0
Eth1 192.168.67.2 mask 255.255.255.0 接入核心交換機,核心交換機接口設為192.168.67.1 mask 255.255.255.0

操作系統:centOS5.5
L2tp服務軟件:xl2tpd 1.2.7 默認服務端口為1701

一、 安裝xl2tp
1、安裝CentOS需要的庫和軟件包:yum install libpcap-devel ppp
2、從http://www.xelerance.com/software/xl2tpd/上下載xl2tpd-1.2.7.tar.gz
3、解壓:tar -zxvf xl2tpd-1.2.7.tar.gz
4、進入該解壓目錄,然後編譯、安裝:
cd xl2tpd-1.2.7
make
make install
5、修改/etc/xl2tpd/xl2tpd.conf,內容如下:
先將默認示例配置文件拷到相應目錄下:
mkdir /etc/xl2tpd
mkdir /var/run/xl2tpd
cp examples/xl2tpd.conf /etc/xl2tpd/


修改文件,注意紅色部分:
vi /etc/xl2tpd/xl2tpd.conf
[global]
listen-addr = 192.166.1.2
;對外拔號服務器地址
; requires openswan-3.1 or higher
; ipsec saref = yes
;
; debug tunnel = yes
;port = 1701
auth file = /etc/ppp/chap-secrets
;認證用戶名密碼的文件路徑
debug tunnel = yes
[lns default]
ip range = 192.168.67.3-192.168.67.254
;給拔號成功的用戶分配的地址池
local ip = 192.168.67.2
;內部轉發數據包的接口的真實IP地址
require chap = yes
refuse pap = yes
require authentication = yes
name = xxbl2tpserver
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
;ppp協議的配置文件路徑
length bit = yes

6、修改/etc/ppp/options.xl2tpd,內容如下:
cp examples/ppp-options.xl2tpd /etc/ppp/options.xl2tpd
vi /etc/ppp/options.xl2tpd

ipcp-accept-local
ipcp-accept-remote
ms-dns 8.8.8.8
ms-dns 221.7.17.21
#給拔號用戶分配dns服務器地址
noccp
auth
crtscts
idle 1800
mtu 1500
mru 1500
nodefaultroute
debug
lock
logfile /var/log/l2tpd.log
#日志文件路徑
proxyarp
connect-delay 5000
#kdebug 2
#record /var/log/l2tpdcontent.log
receive-all
ktune

7、修改用戶認證文件/etc/ppp/chap-secrets,內容如下
# Secrets for authentication using CHAP
# client server secret IP addresses
# Secrets for authentication using CHAP
# client server secret IP addresses
"test" * "test" *

8、編輯啟動、停止服務腳本/etc/init.d/xl2tpd文件,內容如下:
#!/bin/sh
#
# xl2tpd This shell script takes care of starting and stopping l2tpd.
#
# chkconfig: - 80 30
# description: Layer 2 Tunnelling Protocol Daemon (RFC 2661)
#
# processname: xl2tpd
# config: /etc/xl2tpd/xl2tpd.conf
# pidfile: /var/run/xl2tpd.pid
#Servicename
SERVICE=xl2tpd
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
if [ ${NETWORKING} = "no" ]
then
exit 0
fi
[ -x /usr/local/sbin/$SERVICE ] || exit 0
RETVAL=0
start() {
echo -n "Starting $SERVICE: "
if [ ! -d /var/run/xl2tpd ]
then
mkdir /var/run/xl2tpd
fi
daemon /usr/local/sbin/$SERVICE
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SERVICE
echo ""
return $RETVAL
}
stop() {
echo -n "Stopping $SERVICE: "
killproc $SERVICE
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$SERVICE
return $RETVAL
}
restart() {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $SERVICE
RETVAL=$?
;;
restart|reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/$SERVICE ] && restart || :
;;
*)
echo "Usage: $SERVICE {start|stop|status|restart|reload|condrestart}"
exit 1
esac

9、用chmod命令給xl2tpd文件賦予可執行權限。
chmod +x /etc/init.d/xl2tpd
1.2.7版將xl2tpd服務程序默認安裝在/usr/local/sbin/下,而xl2tpd.sh啟動腳本卻是寫的/usr/sbin/,所以要執行以下復制命令
cp /usr/local/sbin/xl2tpd /usb/sbin/

10、將xl2tpd加入到系統服務中去:
chkconfig --add xl2tpd
chkconfig xl2tpd --level 35 on

也可以通過在終端:#xl2tpd -c /etc/xl2tpd/xl2tpd.conf -D 啟動xl2tpd服務,並查看調試信息。

Copyright © Windows教程網 All Rights Reserved