CentOS 5.6 安装L2TP VPN以及2种客户端连接方法
第二层隧道协议L2TP(Layer 2 Tunneling Protocol)是一种工业标准的Internet隧道协议,它使用UDP的1701端口进行通信。L2TP本身并没有任何加密,但是我们可以使用IPSec对L2TP包进行加密。L2TP VPN比PPTP VPN搭建复杂一些。 网络环境:
Eth0: 192.168.58.128/255.255.255.0 DNS:8.8.8.8 (可访问外网) Eth1:192.168.238.129(内网)
(vpn分配的IP网段)10.0.0.0/255.255.0.0
说明,我看了网上许多文档,深受其害。经历了个各种磨难,终于领悟了?以下省略N个字。如果相信我,请往下看。
关闭selinux setenforce 0
关闭防火墙
/etc/init.d/iptables stop
linux同步北京时间 ntpdate ntp.fudan.edu.cn
一、修改包转发设置
复制以下两段代码在终端里运行:
for each in /proc/sys/net/ipv4/conf/* do
echo 0 > $each/accept_redirects echo 0 > $each/send_redirects done
echo 1 >/proc/sys/net/core/xfrm_larval_drop
修改内核设置,使其支持转发,编辑/etc/sysctl.conf文件: vi /etc/sysctl.conf
将“net.ipv4.ip_forward”的值改为1。 使修改生效: sysctl -p
二、安装L2TP(xl2tpd和rp-l2tp)
xl2tpd是由Xelerance Corporation维护的l2tpd应用。但是xl2tpd没有l2tp-control,需要从rp-l2tp这个里面提取。所以要装这两个软件包。 1、安装必备软件:
yum install -y libpcap-devel ppp policycoreutils yum clean all
使用rpm 安装ppp pptpd
安装EPEL(企业级 Linux提供的扩展软件源) 如果是centos 5.x系列,请安装以下文件
rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
【如果是centos 6.x系列,请安装以下文件
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm vi /etc/yum.repos.d/epel.repo 将所有的https改成http yum clean all】 yum安装xl2tpd
yum install -y xl2tpd
2、xl2tpd配置文件: cd /etc/xl2tpd/
cp xl2tpd.conf xl2tpd.conf.bak vi xl2tpd.conf 修改红色字段:
注意local ip后面填写的IP地址不是外网地址,也不是内网地址,而是虚拟网关的IP地址
[lns default]
;最大有65533个客户端
ip range = 10.0.0.2-10.0.255.254 local ip = 10.0.0.1 require chap = yes refuse pap = yes
require authentication = yes name = LinuxVPNserver ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd length bit = yes
3、配置ppp/options.xl2tpd文件: cd /etc/ppp/
cp options.xl2tpd options.xl2tpd.bak vi options.xl2tpd
删除所有内容,增加以下内容: require-mschap-v2 ms-dns 8.8.8.8 ms-dns 8.8.4.4 asyncmap 0 auth crtscts lock
hide-password modem debug
name xl2tpd proxyarp
lcp-echo-interval 30
lcp-echo-failure 4
4、设置拨号用户名和密码:
cp chap-secrets chap-secrets.bak vi chap-secrets
test表示用户名,xl2tpd表示服务类型,123表示密码,*表示允许所以IP地址连接
# Secrets for authentication using CHAP
# client server secret IP addresses
####### redhat-config-network will overwrite this part!!! (begin) ########## ####### redhat-config-network will overwrite this part!!! (end) ############ test xl2tpd 123 *
5、以debug方式启动l2tp,查看有无错误: xl2tpd -D 显示如下:
xl2tpd[3580]: setsockopt recvref[30]: Protocol not available xl2tpd[3580]: This binary does not support kernel L2TP.
xl2tpd[3580]: open_controlfd: Unable to open /var/run/xl2tpd/l2tp-control for reading. 出现以上错误时,需要手动建立xl2tpd目录 mkdir /var/run/xl2tpd 再次执行xl2tpd -D
xl2tpd[3617]: setsockopt recvref[30]: Protocol not available xl2tpd[3617]: This binary does not support kernel L2TP.
xl2tpd[3617]: open_controlfd: Unable to open /var/run/xl2tpd/l2tp-control for reading. [root@NBX1 ppp]# mkdir /var/run/xl2tpd [root@NBX1 ppp]# xl2tpd -D
xl2tpd[3619]: setsockopt recvref[30]: Protocol not available xl2tpd[3619]: This binary does not support kernel L2TP.
xl2tpd[3619]: xl2tpd version xl2tpd-1.3.1 started on NBX1.localdomain PID:3619 xl2tpd[3619]: Written by Mark Spencer, Copyright (C) 1998, Adtran, Inc. xl2tpd[3619]: Forked by Scott Balmos and David Stipp, (C) 2001 xl2tpd[3619]: Inherited by Jeff McAdams, (C) 2002
xl2tpd[3619]: Forked again by Xelerance (www.xelerance.com) (C) 2006 xl2tpd[3619]: Listening on IP address 0.0.0.0, port 1701
说明已经在监听端口了。现在可以在windows上建立L2TP拨号连接了。 三、设置开机启动
chkconfig --level 3 xl2tpd on 启动xl2tp
/etc/init.d/xl2tpd start 查看监听端口
netstat -naptlu | grep xl2tpd
udp 0 0 0.0.0.0:1701 0.0.0.0:*
3671/xl2tpd
Linux L2TP客户端连接方法
关闭selinux setenforce 0
关闭防火墙
/etc/init.d/iptables stop
linux同步北京时间 ntpdate ntp.fudan.edu.cn
安装EPEL(企业级 Linux提供的扩展软件源) 如果是centos 5.x系列,请安装以下文件
rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm 【如果是centos 6.x系列,请安装以下文件
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm vi /etc/yum.repos.d/epel.repo 将所有的https改成http yum clean all】 安装xl2tpd
yum install -y xl2tpd
配置xl2tpd文件 cd /etc/xl2tpd/
cp xl2tpd.conf xl2tpd.conf.bak vi xl2tpd.conf
;VPN名称为testvpn [lac testvpn] ;l2tp帐号 name = test
; l2tp server的IP lns = 192.168.58.128
; pppd拨号时使用的配置文件
pppoptfile = /etc/ppp/peers/testvpn.l2tpd ppp debug = yes
设置拨号配置文件 cd /etc/ppp/peers/ vi testvpn.l2tpd
相关推荐: