Home Archives Categories Tags Docs

CentOS 架设PPTP VPN服务教程

发布时间: 更新时间: 总字数:841 阅读时间:2m 作者: 分享

在网上搜集了一些vpn安装部署的脚本,提交到xiexianbin/vpn,以防后忘。

准备

检测PPP是否开启

[root@ip-172-31-17-56 ~]# cat /dev/ppp 
cat: /dev/ppp: No such device or address
  • 开启成功的标志:cat: /dev/ppp: No such file or directory
  • 未安装标志:cat: /dev/ppp: No such device or address
  • 没有权限标志:cat: /dev/ppp: Permission denied

检测tun/tap是否开启:

[root@ip-172-31-17-56 ~]# cat /dev/net/tun 
cat: /dev/net/tun: File descriptor in bad state

显示结果为上面面的文本,表明通过,可以继续安装。

检测是否ppp:

[root@ip-172-31-17-56 ~]# modprobe ppp-compress-18 && echo yes
yes

安装

[root@ip-172-31-17-56 ~]# yum -y install ppp pptpd
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
bintray-tatsushid-h2o-rpm                                                                                                                                                                         | 1.3 kB  00:00:00     
epel-rpm                                                                                                                                                                                          | 4.3 kB  00:00:00     
rhui-REGION-client-config-server-7                                                                                                                                                                | 2.9 kB  00:00:00     
rhui-REGION-rhel-server-releases                                                                                                                                                                  | 3.5 kB  00:00:00     
rhui-REGION-rhel-server-rh-common                                                                                                                                                                 | 3.8 kB  00:00:00     
(1/6): rhui-REGION-rhel-server-rh-common/7Server/x86_64/updateinfo                                                                                                                                |  31 kB  00:00:00     
(2/6): rhui-REGION-rhel-server-releases/7Server/x86_64/updateinfo                                                                                                                                 | 1.8 MB  00:00:00     
(3/6): rhui-REGION-rhel-server-rh-common/7Server/x86_64/primary_db                                                                                                                                | 116 kB  00:00:00     
(4/6): rhui-REGION-rhel-server-releases/7Server/x86_64/primary_db                                                                                                                                 |  34 MB  00:00:01     
(5/6): epel-rpm/updateinfo                                                                                                                                                                        | 760 kB  00:00:03     
(6/6): epel-rpm/primary_db                                                                                                                                                                        | 4.6 MB  00:00:04     
Package ppp-2.4.5-33.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package pptpd.x86_64 0:1.4.0-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================================================================
 Package                                           Arch                                               Version                                                 Repository                                            Size
=========================================================================================================================================================================================================================
Installing:
 pptpd                                             x86_64                                             1.4.0-2.el7                                             epel-rpm                                              80 k

Transaction Summary
=========================================================================================================================================================================================================================
Install  1 Package

Total download size: 80 k
Installed size: 182 k
Downloading packages:
pptpd-1.4.0-2.el7.x86_64.rpm                                                                                                                                                                      |  80 kB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pptpd-1.4.0-2.el7.x86_64                                                                                                                                                                              1/1 
  Verifying  : pptpd-1.4.0-2.el7.x86_64                                                                                                                                                                              1/1 

Installed:
  pptpd.x86_64 0:1.4.0-2.el7                                                                                                                                                                                             

Complete!
[root@ip-172-31-17-56 ~]# 

配置pptp

首先我们要编辑/etc/pptpd.conf文件:

[root@ip-172-31-17-56 ~]# vim /etc/pptpd.conf
localip 192.168.0.1
remoteip 192.168.2.10-200

接下来再编辑/etc/ppp/options.pptpd

[root@ip-172-31-17-56 ~]# vim /etc/ppp/options.pptpd
ms-dns 8.8.8.8
ms-dns 8.8.4.4
ms-dns 223.5.5.5
ms-dns 223.6.6.6

设置pptp VPN账号密码。编辑/etc/ppp/chap-secrets

[root@ip-172-31-17-56 ~]# cat /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client	server	secret			IP addresses
foo pptpd foo123456 *
[root@ip-172-31-17-56 ~]# 

修改内核设置支持转发。编辑/etc/sysctl.conf文件:

[root@ip-172-31-17-56 ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward=1
#net.ipv4.tcp_syncookies=1

同时在net.ipv4.tcp_syncookies=1前面加# :

sysctl -p

添加iptables转发规则(172.31.17.56为你的VPS的公网IP地址):

iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 172.31.17.56
iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE
service iptables save
systemctl restart pptpd

脚本安装

wget https://raw.githubusercontent.com/XieXianbin/vpn/master/pptp/CentOS7-pptp-firewalld.sh
chmod +x ./CentOS7-pptp-firewalld.sh
./CentOS7-pptp-firewalld.sh -u your_username -p your_password

windows 链接vpn

防火墙

TCP 1723和47

问题处理

  • 619 问题

    rm /dev/ppp mknod /dev/ppp c 108 0
    
  • 651 问题

方法一:卸载virtual box等软件。

方法二:logwtmp 不兼容问题:

[root@ip-172-31-17-56 ~]# vi /etc/pptpd.conf
...
#logwtmp
...
  • Maximum of 100 connections reduced to 91, not enough IP addresses given

错误日志:

Mar 24 10:36:28 ip-172-31-17-56 systemd: Stopping PoPToP Point to Point Tunneling Server...
Mar 24 10:36:28 ip-172-31-17-56 systemd: Started PoPToP Point to Point Tunneling Server.
Mar 24 10:36:28 ip-172-31-17-56 systemd: Starting PoPToP Point to Point Tunneling Server...
Mar 24 10:36:28 ip-172-31-17-56 pptpd[5521]: MGR: Maximum of 100 connections reduced to 91, not enough IP addresses given
Mar 24 10:36:28 ip-172-31-17-56 pptpd[5521]: MGR: Manager process started
Mar 24 10:36:28 ip-172-31-17-56 pptpd[5521]: MGR: Maximum of 91 connections available

/etc/pptpd.conf中,remoteip范围配置大些。

完毕。

相关文章
最近更新
最新评论
加载中...