bingoogolapple.github.io
bingoogolapple.github.io copied to clipboard
在 Centos 上安装 PPTP VPN 服务
配置 PPTP 服务端
- 先看看你的主机是否支持 pptp,返回结果为 yes 就表示通过
modprobe ppp-compress-18 && echo yes
- 是否开启了TUN,有的虚拟机主机需要开启,返回结果为cat: /dev/net/tun: File descriptor in bad state。就表示通过
cat /dev/net/tun
- 安装 ppp , pptpd
yum install update
yum -y install ppp pptpd
- 编辑配置文件「vi /etc/pptpd.conf」,删除下列两行命令符前面的井号,「localip 和 remoteip 分别是 vpn 的网关地址和 vpn 拨号获取地址段。可以根据需要进行调整」
#localip 192.168.0.1
#remoteip 192.168.0.234-238,192.168.0.245
- 编辑文件「vi /etc/ppp/options.pptpd」设置谷歌或阿里巴巴 DNS
- 输入命令「vi /etc/ppp/chap-secrets」设置 pptpd 的用户名和密码。按照「用户名 pptpd 密码 IP地址」的格式输入,每一项用空格隔开,每行一个账号
- 使用「vi /etc/ppp/ip-up」命令,在「[ -x /etc/ppp/ip-up.local ] && /etc/ppp/ip-up.local "$@"」的下面行添加「ifconfig ppp0 mtu 1472」设置最大传输单元 MTU
- 「vi /etc/sysctl.conf」添加一行「net.ipv4.ip_forward=1」到末尾保存,然后运行「sysctl -p」
- 添加 iptables 转发规则
yum install iptables-services
systemctl enable iptables
systemctl start iptables
# 47.52.23.xx 是你的服务器的公网
iptables -t nat -A POSTROUTING -s 192.168.0.234/24 -j SNAT --to 47.52.23.xx
iptables -t nat -A POSTROUTING -s 192.168.0.234/24 -j MASQUERADE
iptables -I INPUT -p tcp --dport 1723 -j ACCEPT
iptables -I INPUT -p tcp --dport 47 -j ACCEPT
iptables -I INPUT -p gre -j ACCEPT
service iptables save
- 保险起见,到了这里应该重启一下 pptpd 服务和 iptables 服务生效
systemctl restart iptables.service
systemctl enable iptables.service
systemctl restart pptpd
systemctl enable pptpd.service
- 使用如下命令设置 pptpd 和 iptables 自启动
chkconfig iptables on
chkconfig pptpd on
- 阿里云配置安全组规则