搭建清單:
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