CentOS VPS安装PPTP VPN(适用于XEN和OpenVZ)

开始安装PPTP前,有一些基本前提需要知道,比如VPS是否支持PPP啦,是否支持MPPE啦等等。怎么知道呢?最简单的办法,就是直接咨询VPS提供商。

安装ppp

yum install ppp

安装PPTPd,这个有两种办法安装,一种在RPM二进制包的安装,一种是从源码编译安装。一般而言我都会推荐自己编译源码,但是PPTPd的源码编译略坑,所以还是推荐安装RPM包。

rpm版安装:

前往http://poptop.sourceforge.net/yum/stable/packages/或 https://code.google.com/p/acelnmp/downloads/list,下载rpm后,执行

rpm -ivh pptpd-1.3.4-2.rhel5.i386.rpm

编译安装pptpd,不建议

wget http://nchc.dl.sourceforge.net/project/poptop/pptpd/pptpd-1.3.4/pptpd-1.3.4.tar.gz

tar zxf pptpd-1.3.4.tar.gz

cd  pptpd-1.3.4

rpm -ivh pptpd-1.3.4-2.rhel5.i386.rpm

查看/usr/lib/pptpd是否存在,如果不存在,则执行:

mkdir /usr/lib/pptpd

ln -s /usr/local/lib/pptpd/pptpd-logwtmp.so /usr/lib/pptpd/pptpd-logwtmp.so

配置文件/etc/pptpd.conf:

option /etc/ppp/options.pptpd
logwtmp
localip 192.168.2.1
remoteip 192.168.2.2-250

配置文件/etc/ppp/options.pptpd:

name pptpd

refuse-pap
refuse-chap
refuse-mschap
# Require the peer to authenticate itself using MS-CHAPv2 [Microsoft
# Challenge Handshake Authentication Protocol, Version 2] authentication.
require-mschap-v2
# Require MPPE 128-bit encryption
# (note that MPPE requires the use of MSCHAP-V2 during authentication)
require-mppe-128
# }}}

ms-dns 8.8.8.8
ms-dns 8.8.4.4

proxyarp

lock

nologfd

设置自动启动脚本/etc/init.d/pptpd:

#!/bin/sh
#
# Startup script for pptpd
#
# chkconfig: - 85 15
# description: PPTP server
# processname: pptpd
# config: /etc/pptpd.conf

# Source function library.
. /etc/rc.d/init.d/functions
# See how we were called.
case "$1" in
start)
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/tcp_syncookies

iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE
iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT

echo -n "Starting pptpd: "
if [ -f /var/lock/subsys/pptpd ] ; then
echo
exit 1
fi
daemon /usr/sbin/pptpd
echo
touch /var/lock/subsys/pptpd
;;
stop)
iptables -t nat -D POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE
iptables -D INPUT -p udp -m udp --dport 53 -j ACCEPT

echo -n "Shutting down pptpd: "
killproc pptpd
echo
rm -f /var/lock/subsys/pptpd
;;
status)
status pptpd
;;
condrestart)
if [ -f /var/lock/subsys/pptpd ]; then
$0 stop
$0 start
fi
;;
reload|restart)
$0 stop
$0 start
echo "Warning: a pptpd restart does not terminate existing "
echo "connections, so new connections may be assigned the same IP "
echo "address and cause unexpected results.  Use restart-kill to "
echo "destroy existing connections during a restart."
;;
restart-kill)
$0 stop
ps -ef | grep pptpd | grep -v grep | grep -v rc.d | awk '{print $2}' | uniq | xargs kill 1> /dev/null 2>&1
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|restart-kill|status}"
exit 1
esac

exit 0

最后让脚步开机启动:

chmod +x /etc/init.d/pptpd

chkconfig --level 345 pptpd on

service pptpd start

如果你的VPS是OpenVZ,应该把上面的“iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE”改为:

iptables -t nat -A POSTROUTING -s  192.168.2.0/24 -j SNAT --to-source 你的VPS的IP

同时把上面的“iptables -t nat -D POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE”改为:

iptables -t nat -D POSTROUTING -s  192.168.2.0/24 -j SNAT --to-source 你的VPS的IP

设置pptp的密码:

vi /etc/ppp/chap-secrets
格式为“用户名 pptpd 密码 *”

常见问题:

1:如果连接的时候,出现619错误,则运行:

rm -r /dev/ppp
mknod /dev/ppp c 108 0

然后重新启动你的VPS。

2:如果连接的时候,出现800错误,这是因为虚拟机内核不支持MPPE,这时候PPTP也没意义了,因为已经是明文的了。

3:如果还有其他错误或上述错误一直存在,请使用

tail /var/log/messages

查看系统日志解决

1 comment

  1. ai says:

    博主是否能帮忙安装个plowshare4

Leave a comment