User Tools

Site Tools


command:setup-vpn

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

command:setup-vpn [2021/08/22 12:45] – created morgan0329command:setup-vpn [2021/08/22 12:46] (current) morgan0329
Line 1: Line 1:
 +====== centos7搭建pptp的vpn ======
 +参考:https://blog.csdn.net/weixin_39764494/article/details/111842286
 +<code>
 +1查看是否支持:
 +[root@VM-34-255-centos ~]# modprobe ppp-compress-18 && echo yes
 +yes
 +[root@VM-34-255-centos ~]# cat /dev/ppp
 +cat: /dev/ppp: No such device or address
  
 +2禁用firewalld防火墙和安装需要的包
 +#停止和禁用firewalld
 +[root@VM-34-255-centos ~]# systemctl stop firewalld
 +[root@VM-34-255-centos ~]# systemctl disable firewalld
 +#增加epel yum源
 +[root@VM-34-255-centos ~]# yum install epel-release -y
 +#安装需要的包
 +[root@VM-34-255-centos ~]# yum install ppp ppp-devel pptpd iptables iptables-services -y
 +
 +3修改配置文件
 +vim /etc/pptpd.conf  #找到此处去掉前面注释
 +localip 10.105.34.255  #内网ip地址(云服务器的内网地址)
 +remoteip 192.168.0.10-20  #自定义分配给客户端的网段
 +
 +vim /etc/ppp/options.pptpd
 +#修改成如下配置
 +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
 +
 +4修改认证配置文件
 +vim /etc/ppp/chap-secrets
 +# client    server    secret            IP addresses
 +test    pptpd 123456 *
 +
 +5打开系统转发 并应用生效
 +vim /etc/sysctl.conf
 +net.ipv4.ip_forward=1
 +sysctl -p
 +
 +6、启动pptpd服务
 +systemctl start pptpd
 +
 +7开放需要的端口(iptables和云服务器的安全组)
 +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 22 -j ACCEPT
 +iptables -A INPUT -p tcp --dport 80 -j ACCEPT
 +iptables -A INPUT -p tcp --dport 443 -j ACCEPT
 +iptables -A INPUT -p tcp --dport 1723 -j ACCEPT
 +iptables -A INPUT -p gre -j ACCEPT
 +
 +service iptables save  #保存规则
 +systemctl restart iptables  #重启生效
 +记得打开了阿里云的安全组端口
 +
 +8增加转发规则,和修改mtu的大小,为了可以连上vpn后上网
 +#注意这里网段和上面配置文件网段一致,eth0和本机网卡名称一致(本机只有eth0和lo)
 +iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE
 +service iptables save   #保存规则
 +systemctl restart iptables   #重启生效
 +
 +#修改MTU默认值1396为1500,在exit 0前面加一句
 +vim /etc/ppp/ip-up
 +.......
 +
 +ifconfig $1 mtu 1500
 +
 +exit 0
 +
 +systemctl restart pptpd  #重启下pptpd服务
 +
 +
 +万一遇到问题:
 +tail -f /var/log/messages   #查看日志
 +systemctl status pptpd  #查看pptpd的状态
 +</code>

Except where otherwise noted, content on this wiki is licensed under the following license: 沪ICP备12046235号-2
Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki