++++++++++++++++++++++++++++++++++++++++++++
秀脱之vpn服务器配置pptpd实战笔记
QQ: 6541657
Email: xiutuo@gmail.com
-----------------------------------
环境:
在可以上网的局域网内选择一台xp机器(有一个网卡,这里叫eth_xp)安装虚拟机vm5,
并安装centos5,为其增加了俩个网卡eth0,eth1。其中centos作为vpn服务器,
xp作为客户端。现在是在iptables防火墙上使用vpn服务器.
vpn服务器和客户端的ip分:公网ip,内网ip,虚拟ip
其中俩个网络中的必须有公网ip,
俩个网络中的内网ip可相同和不同,
俩个网络中虚拟ip必须相同
各网卡ip分配情况:
eth_xp: 这里相当于vpn客户端的公网ip
ip:192.168.1.10
netmask:255.255.255.0
gateway:192.168.1.1
dns:202.202.202.200 (假设是这样的,根据isp提供的来设置,也可以是动态分配的)
eth0: 这里相当于vpn服务端的公网ip
ip:192.168.1.100
netmask:255.255.255.0
gateway:192.168.1.1
dns:202.202.202.200 (假设是这样的,根据isp提供的来设置,也可以是动态分配的)
eth1:这里相当于vpn服务端的内网ip
ip:10.10.10.10
netmask:255.255.255.0
centos中vpn的服务器虚拟ip:10.10.11.10,vpn服务名叫xt
(由配置文件/etc/ppp/options.pptpd中name字段定义)
分配给xp中vpn客户端所在网络的ip范围:10.10.11.100--200
分配给xp 中vpn的ip为:10.10.11.100
xp通过vpn客户端连入vpn服务器后能上网。
++++++++++++++++++++++++++++++++++++++++++++
centos服务器所用软件
pptpd
ppp
并且开启了selinux。
xp的vpn客户端,直接通过xp自带网络新建连接中的vpn
一:vpn服务器pptp安装和配置
centos服务器vpn软件安装:
# rpm -qa | grep ppp
# rpm -qa | grep pptpd
如果没有任何显示,则
0.查看内核是否加载 mppe 模块
# lsmod | grep ppp
ppp_async 16065 0
crc_ccitt 6081 1 ppp_async
ppp_mppe 17792 0
ppp_generic 32660 2 ppp_async,ppp_mppe
slhc 11201 1 ppp_generic
说明pptp 所又模块加载成功
1.安装ppp
yum -y install ppp
2.安装pptpd,centos没有自带,请用redhat5的光盘软件包安装
rpm -ivh *pptpd*.rpm,或者通过yum方式
# vim /etc/yum.repos.d/Doylenet.repo
[doylenet]
name=Doylenet custom repository for CentOS
baseurl=http://files.doylenet.net/linux/yum/centos/5/i386/doylenet/
gpgcheck=1
gpgkey=http://files.doylenet.net/linux/yum/centos/RPM-GPG-KEY-rdoyle
enabled=1
# yum update (可省略)
# yum install pptpd
或者源码安装
# tar xzvf pptpd-1.3.4.tar.gz
# cd pptpd-1.3.4
# ./configure
# make && make install
3.安装好后,查看
[root@xt]# rpm -qa | grep pptpd
pptpd-1.3.4-1
[root@xt]# rpm -qa | grep ppp
rp-pppoe-3.5-32.1
ppp-2.4.4-1.el5
4.配置vpn服务
# vi /etc/pptpd.conf
把配置文件最后改成
option /etc/ppp/options.pptpd
#开启debug调试模式,通过/var/log/message 查看错误日志
debug
# vpn服务器虚拟ip分配
## vpn服务器虚拟ip
localip 10.10.11.10
## vpn客户端所在网络虚拟ip范围
remoteip 10.10.11.100-200
vi /etc/ppp/options.pptpd
以下俩行做修改
# vpn服务名定义
name xt
# 开启debug调试模式,方便查看出错日志查看/var/log/message
debug
vi /etc/ppp/chap-secrets 增加如下内容
#为vpn客户端的xp机器分配虚拟ip
# 字段分别为 登入用户名 vpn服务器名 登陆密码 登入时分配的ip
# 其中vpn服务器名必须和配置文件/etc/ppp/options.pptpd中name字段定义的要一样。
"xiutuo" xt "123456" 10.10.11.101
或者使用 vpnuser 命令
例:
# vpnuser add vpntest test123
删除用户:
# vpnuser del vpntest
5.启动vpn
# service pptpd start
二:vpn客户端配置和连接
1.xp下vpn客户端
配置建立vpn连接:
网络邻居属性--创建一个新连接--下一步---选择连接到我的工作场所的网络--下一步
--虚拟专用网络--下一步--填写一个公司名:testvpn--下一步
--输入vpn服务器centos的公网ip:192.168.1.100---下一步
--选择不拨此连接--下一步---选择在桌面上显示此快捷方式--完成。
点击xp桌面的testvpn连接,进入vpn服务器所在网络,连接成功,
在xp中使用putty或者其他远程ssh登入工具(登入是vpn服务的虚拟ip:10.10.11.10)。无法登入。
查看
# cat /var/log/messages,有以下错误,原来是selinux在捣鬼。
Jun 4 12:02:12 xt setroubleshoot:
SELinux is preventing /usr/sbin/pppd (pppd_t) "write" access to wtmp (wtmp_t).
For complete SELinux messages. run sealert -l 8e94e100-d640-4882-8425-71a8d680f6f2
根据错误提示执行
# sealert -l 8e94e100-d640-4882-8425-71a8d680f6f2
提示信息如下,
----------------------------------------------------------------
Summary
SELinux is preventing /usr/sbin/pppd (pppd_t) "write" access to wtmp
(wtmp_t).
Detailed Description
SELinux denied access requested by /usr/sbin/pppd. It is not expected that
this access is required by /usr/sbin/pppd and this access may signal an
intrusion attempt. It is also possible that the specific version or
configuration of the application is causing it to require additional access.
Please file a http://bugzilla.redhat.com/bugzilla/enter_bug.cgi against this
package.
Allowing Access
Sometimes labeling problems can cause SELinux denials. You could try to
restore the default system file context for wtmp, restorecon -v wtmp. There
is currently no automatic way to allow this access. Instead, you can
generate a local policy module to allow this access - see
http://fedora.redhat.com/docs/selinux-faq-fc5/#id2961385 - or you can
disable SELinux protection entirely for the application. Disabling SELinux
protection is not recommended. Please file a
http://bugzilla.redhat.com/bugzilla/enter_bug.cgi against this package.
Changing the "pppd_disable_trans" boolean to true will disable SELinux
protection this application: "setsebool -P pppd_disable_trans=1."
The following command will allow this access:
setsebool -P pppd_disable_trans=1
Additional Information
Source Context root:system_r:pppd_t
Target Context system_u:object_r:wtmp_t
Target Objects wtmp [ file ]
Affected RPM Packages ppp-2.4.4-1.el5 [application]
Policy RPM selinux-policy-2.4.6-104.el5
Selinux Enabled True
Policy Type targeted
MLS Enabled True
Enforcing Mode Enforcing
Plugin Name plugins.disable_trans
Host Name xt
Platform Linux xt 2.6.18-53.el5 #1 SMP Mon Nov 12 02:22:48
EST 2007 i686 i686
Alert Count 4
Line Numbers
Raw Audit Messages
avc: denied { write } for comm="pppd" dev=sda3 egid=0 euid=0
exe="/usr/sbin/pppd" exit=-13 fsgid=0 fsuid=0 gid=0 items=0 name="wtmp" pid=4794
scontext=root:system_r:pppd_t:s0 sgid=0 subj=root:system_r:pppd_t:s0 suid=0
tclass=file tcontext=system_u:object_r:wtmp_t:s0 tty=(none) uid=0
---------------------------------------
其中
The following command will allow this access:
setsebool -P pppd_disable_trans=1
提到了解决方法,好,执行
# setsebool -P pppd_disable_trans=1
好了,此时xp可以通过putty登入了(记得登入ip是vpn的虚拟ip:10.10.11.10),
但是xp无法上网了呵呵。
2.linux下vpn客户端配置和连接
a. 安装了 PPP 软件包。
# rpm -qa | grep ppp
ppp-2.4.4-1.el5
也可以这样来找vpn客户端程序pppd属于那个软件包
# which pppd
/usr/sbin/pppd
# rpm -qf /usr/sbin/pppd
ppp-2.4.4-1.el5
安装pppd
# rpm -ivh ppp-2.4.4-1.el5.rpm
如果是源码安装请下载源码软件包安装
# cd pptp目录
# ./configure
# make
# make install
b.配置 PPTP 客户端:
1) 给PPTP 客户端配置拨号时使用的帐号信息:
# vi /etc/ppp/chap-secrets
# 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) ############
"xiutuo" xt "123456" *
其中前面3个字段要与在VPN服务器上建立的帐号的相应字段一致,
第4个字段可以用 * 号填充,表示地址由服务器端的配置决定。
2)配置拨号属性:
在/etc/ppp/peers/建立一个文件,文件名任意,这里我定义为xiutuotest
# vi /etc/ppp/peers/xiutuotest
# tunnel bjlt, written by pptpconfig $Revision: 1.2 $
# name of tunnel, used to select lines in secrets files
# (vpn)pptp服务器定义的的名称,即服务端(# vpn服务名定义)节定义的值
remotename xt
# name of tunnel, used to name /var/run pid file
# tunel名定义,给pid(/var/run/xt)文件命名,名字任意取
# linkname的定义可以注释掉
linkname xtvpn
# name of tunnel, passed to ip-up scripts
#定义ipparam,名字任取,此配置可以注释掉
ipparam xt
# data stream for pppd to use
# 定义vpn服务器的公网ip
pty "pptp 192.168.1.10 --nolaunchpppd "
# domain and username, used to select lines in secrets files
# 定义域名或者用户名,从/etc/ppp/chap-secrets文件从读取
# 此节可以注释
name xiutuo
# do not require the server to authenticate to our client
noauth
# adopt defaults from the pptp-linux package
file /etc/ppp/options.pptp
# end of tunnel file
c.用pppd连接vpn服务器
# pppd call xiutuotest
# tail -f /var/log/messages
xt pppd[2227]: MPPE 128-bit stateless compression enabled!
xt pppd[2227]: local IP address 10.10.11.100
xt pppd[2227]: remote IP address 10.10.11.10
出现这个就是ok啦
d.让vpn客户端访问vpn服务端内的局域网(含vpn服务器),在vpn客户端机器增加路由
# route add -host vpn客户端虚拟ip gw vpn服务器虚拟ip dev ppp0(看你这个拨号是数字是几了 呵呵,有可能是1,2,3什么的)
这里为
# route add -host 10.10.11.100 gw 10.10.11.10 dev ppp0
或 # route add -host vpn客户端虚拟ip gw vpn服务器虚拟ip
这里为
# route add -host 10.10.11.100 gw 10.10.11.10
# route add -net vpn客户端虚拟网段地址 gw vpn服务器虚拟ip dev ppp0 (看你这个拨号是数字是几了 呵呵,有可能是1,2,3什么的)
这里为
# route add -net 10.10.0.0/16 gw 10.10.11.10 dev ppp0
或 # route add -net vpn客户端虚拟网段地址 gw vpn服务器虚拟ip
# route add -net 10.10.0.0/16 gw 10.10.11.10
也可以用
# ip route add vpn客户端虚拟ip via vpn服务器虚拟ip
这里为
# ip route add 10.10.11.100 via 10.10.11.10
或者
# ip route add vpn客户端虚拟网段地址 via vpn服务器虚拟ip
这里为
# ip route add 10.10.0.0/16 via 10.10.11.10
为了更好的监测vpn运行状态,也可以不加以上静态路由,可以在linux中的vpn客户端的iptables做snat
# iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -d 10.10.0.0/16 -j SNAT --to-source 10.10.11.10
验证路由
# traceroute vpn服务器内网的其中一台机器的ip
e.让vpn客户端ssh访问vpn服务器本身
可以直接用
# ssh 用户@vpn服务器虚拟ip
这里为
# ssh root@10.10.11.10
三.解决vpn客户端上网问题:
以下步骤在vpn服务器端配置
a.
开启ip转发
在centos系统中设置:
# echo 1 > /proc/sys/net/ipv4/ip_forward
或者
-----------------------
# vi /etc/sysctl ,
把 net.ipv4.ip_forward = 0 改成net.ipv4.ip_forward = 1
使设置生效
# sysctl -p
-----------------------
b.iptables做nat
# iptables -Z
# iptables -F
# iptables -X
# iptables -t nat -A POSTROUTING -j SNAT --to 192.168.1.100
# service iptables save
# service iptables restart
# 其中192.168.1.100为vpn服务器的相当于公网的ip
四.查看vnp服务器运行情况
以下步骤在vnp服务器执行
a.启动程序:service pptpd start
b.检验程序是否启动:
# ps -aux | grep pptpd ----查看进程
# netstat -anp | grep 1723 ----查看端口(监听的是1723端口)
tcp 0 0 0.0.0.0:1723 0.0.0.0:* LISTEN 4517/pptpd
tcp 0 0 192.168.1.100:1723 192.168.1.10:4215 ESTABLISHED 5034/pptpd
c.当xp连接了vpn时,centos下运行
# ifconfig
[root@xt ]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E7:AC:5D
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee7:ac5d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:18723 errors:0 dropped:0 overruns:0 frame:0
TX packets:19870 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3686214 (3.5 MiB) TX bytes:4077626 (3.8 MiB)
Interrupt:185 Base address:0x1400
eth1 Link encap:Ethernet HWaddr 00:0C:29:E7:AC:67
inet addr:10.10.10.10 Bcast:10.10.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee7:ac67/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:20361 errors:0 dropped:0 overruns:0 frame:0
TX packets:98 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1900766 (1.8 MiB) TX bytes:17437 (17.0 KiB)
Interrupt:169 Base address:0x1480
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:32 errors:0 dropped:0 overruns:0 frame:0
TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2248 (2.1 KiB) TX bytes:2248 (2.1 KiB)
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.10.11.10 P-t-P:10.10.11.100 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1396 Metric:1
RX packets:2224 errors:0 dropped:0 overruns:0 frame:0
TX packets:2541 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:268780 (262.4 KiB) TX bytes:1362642 (1.2 MiB)
五:查看vpn客户端拨入vpn后运行情况
1.windows下
xp拨入vnp服务器后
windows xp下:开始--运行,输入cmd,再输入ipconfig
PPP adapter testvpn:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 10.10.11.100
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 10.10.11.100
2. linux下
linux拨入vnp服务器后
# ifconfig
……
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.10.11.100 P-t-P:10.10.11.10 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1396 Metric:1
RX packets:60 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:7056 (6.8 KiB) TX bytes:92 (92.0 b)
附录
------------------------------------
* 使用route 命令配置路由表 */
//添加到主机路由
# route add –host 192.168.168.110 dev eth0:1
# route add –host 192.168.168.119 gw 192.168.168.1
//添加到网络的路由
# route add –net IP netmask MASK eth0
# route add –net IP netmask MASK gw IP
# route add –net IP/24 eth1
//添加默认网关
# route add default gw IP
//删除路由
# route del –host 192.168.168.110 dev eth0