搭建清单:
Centos7 (我这里使用腾讯云的服务器)
ppp和pptpd 包
iptables (我这里使用iptables)
win10客户端(连接测试使用)
1、查看是否支持
[root@VM_centos ~]# modprobe ppp-compress-18 && echo yes
yes
[root@VM_centos ~]# cat /dev/ppp
cat: /dev/ppp: 没有那个设备或地址
2、禁用firewalld防火墙和安装需要的包
停止和禁用firewalld
[root@VM_centos ~]# systemctl stop firewalld
[root@VM_centos ~]# systemctl disable firewalld
增加epel yum源
[root@VM_centos ~]# yum install epel-release -y
安装需要的包
[root@VM_centos ~]# yum install ppp ppp-devel pptpd iptables iptables-services -y
3、修改配置文件pptpd.conf option.pptpd
[root@VM_centos ~]# vim /etc/pptpd.conf
找到此处去掉前面注释
localip xxx.xxx.xxx.xxx #自定义一个ip或者内网ip地址
remoteip 192.168.0.10-20 #自定义分配给客户端的网段和地址池
[root@VM_centos ~]# vim /etc/ppp/options.pptpd
修改下ms-dns,和添加一个日志文件,其他默认都开启的不用动即可
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
ms-dns 8.8.8.8
ms-dns 114.114.114.114
proxyarp
lock
nobsdcomp
novj
novjccomp
nologfd
logfile /var/log/pptpd.log
4、修改用户认证配置文件chap-secrets
[root@VM_centos ~]# vim /etc/ppp/chap-secrets
添加用户格式:用户名 pptpd 密码 *
Secrets for authentication using CHAP
client server secret IP addresses
test * 123456 *
5、打开系统ipv4转发 sysctl.conf
[root@VM_centos ~]# vim /etc/sysctl.conf
有此项的话修改数值为1 没有的新添加一条
net.ipv4.ip_forward=1
应用生效
[root@VM_centos ~]# sysctl -p
6、启动pptpd服务
[root@VM_centos ~]# systemctl start pptpd
7、开放需要的端口(iptables和云服务器的安全组),此步操作完就可以先测试下是否可以连接了
1723端口和gre协议是必须添加的,其他规则的端口不用按我的这个添加
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
iptables -A INPUT -p tcp --dport 1723 -j ACCEPT
iptables -A INPUT -p gre -j ACCEPT
保存规则
[root@VM_centos ~]# service iptables save
重启生效
[root@VM_centos ~]# systemctl restart iptables
PTVPN2.png
8、增加转发规则,和修改mtu的大小,为了可以连上vpn后上网
注意这里网段和上面配置文件(/etc/pptpd.conf)网段子网一致,eth0和本机网卡名称一致(本机只有eth0和lo)
[root@VM_centos ~]# iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE
保存规则
[root@VM_centos ~]# service iptables save
重启生效
[root@VM_centos ~]# systemctl restart iptables
修改MTU默认值1396为1500,在exit 0前面加一句
[root@VM_centos ~]# vim /etc/ppp/ip-up
.......
ifconfig $1 mtu 1500
exit 0
重启下pptpd服务
[root@VM_centos ~]# systemctl restart pptpd