[转]CentOS Linux VPS架设PPTP VPN教程[图解]

======130115 更新pptpd到pptpd-1.3.4-2======
======151213 更新CentOS6 yum方式安装pptpd源======
======180127 更新CentOS7 yum方式安装pptpd======
======190714 更新CentOS6 CentOS7安装流程======

测试的系统为CentOS5.6,架设VPN的教程:
一、首先检查你VPS的PPP和TUN有没有启用:
TUN设备是Linux下的虚拟网卡。

cat /dev/ppp
cat /dev/net/tun

显示结果为:cat: /dev/ppp: No such device or address和cat: /dev/net/tun: File descriptor in bad state,表明通过,上述两条只要有一个没通过都不行。如果没有启用,你可以给VPS提供商Submit 一个 Ticket请求开通:

Hello

Could you enabled TUN-TAP for me? I want run pptp-vpn on my VPS.
Thank you.

确认PPP和TUN启用后,开始安装ppp和iptables:

yum install -y ppp iptables

二、安装pptp:

rpm -ivh http://acelnmp.googlecode.com/files/pptpd-1.3.4-2.rhel5.i386.rpm (32位系统)

rpm -ivh http://acelnmp.googlecode.com/files/pptpd-1.3.4-2.rhel5.x86_64.rpm (64位系统)



CentOS6.X系统,yum方式安装:

rpm -Uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
yum install pptpd

CentOS7.x系统,yum方式安装:

yum install epel-release
yum install pptpd iptables iptables-services

三、配置pptp,编辑/etc/pptpd.conf文件:
pptp协议使用基于Microsoft点到点加密技术MPPE。

vim /etc/pptpd.conf

把下面字段前面的#去掉:

localip 192.168.0.1
remoteip 192.168.0.234-238,192.168.0.245

四、配置ppp,编辑/etc/ppp/options.pptpd 文件:
pptp协议使用基于ppp协议的身份验证方式。

vim /etc/ppp/options.pptpd

去掉ms-dns前面的#,并使用Google的DNS服务器,修改成如下字段:

ms-dns 8.8.8.8
ms-dns 8.8.4.4

五、设置VPN账号密码,编辑/etc/ppp/chap-secrets这个文件:

vim /etc/ppp/chap-secrets

六、修改内核设置,使其支持转发,编辑 /etc/sysctl.conf 文件:

CentOS6.x系统修改:

vim /etc/sysctl.conf
将“net.ipv4.ip_forward”的值改为1,同时在“net.ipv4.tcp_syncookies = 1”前面加#

CentOS7.x系统修改:

vi /usr/lib/sysctl.d/50-default.conf
vi /etc/sysctl.d/90-override.conf
50-default.conf文件更新kernal版本会自动覆盖,所以创建在/etc/sysctl.d/90-override.conf里面

添加:

net.ipv4.ip_forward = 1

七、使sysctl.conf配置文件生效并添加iptables转发规则:
CentOS7.x系统先执行:

iptables -F
sysctl -p

CentOS6.x、CentOS7.x执行:

sysctl -p
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j SNAT –to-source ***.***.***.***
(***.***.***.***为你VPS的公网IP地址)
查看命令:iptables -L -t nat
删除命令:
iptables -L -t nat –line-numbers
iptables -t nat -D POSTROUTING 编号

CentOS6.x执行:

保存iptables转发规则:

/etc/init.d/iptables save

重启iptables:

/etc/init.d/iptables restart

重启pptp服务:

/etc/init.d/pptpd restart

设置开机自动运行pptp服务:

chkconfig –level 345 pptpd on

设置开机自动运行iptables服务:

chkconfig –level 345 iptables on

CentOS7.x系统执行:

#保存转发规则
service iptables save
#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
#重启iptables
systemctl restart iptables.service
#设置开机自启动
systemctl enable iptables.service
#重启pptp
systemctl restart pptpd.service
#设置开机自启动
systemctl enable pptpd.service

至此,Linux VPS架设VPN完成,如果连接出现错误619则输入如下命令解决:

rm /dev/ppp
mknod /dev/ppp c 108 0
chmod 600 /dev/ppp

如果出现错误734则修改/etc/ppp/options.pptpd文件,在require-mppe-128字段前面加#然后windows客户端连接按下图设置即可。

win10如果连接不上,打开Routing and Remote Access服务,再尝试

八、其他
1、记一次openvz vps连接不上的问题排查:
vi /etc/ppp/options.pptpd
1)找到# Logging
将debug、dump前的注释去掉
2)找到nologfd
将其注释
下一行加上logfile /var/log/pptpd.log
3)连接查看日志
Plugin /usr/lib64/pptpd/pptpd-logwtmp.so loaded.
pptpd-logwtmp: $Version$
Couldn’t open the /dev/ppp device: No such file or directory
说明还是ppp有问题
4)如果已经打开了ppp和net-tun,重新建立ppp
mknod /dev/ppp c 108 0
2、vps可以连上但不能转发
检查内核转发是否开启:
sysctl -a | grep ip_forward
显示如下:
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_use_pmtu = 0
如已经添加但还是为0,可尝试重启vps

本文转自:http://www.lingchen.org/?p=6

《[转]CentOS Linux VPS架设PPTP VPN教程[图解]》上的2个想法

评论已关闭。