rect 写入 服务器 ets 添加 cto ubuntu 成功 工作区
- 检查是否支持
- 若你使用XEN架构的VPS,下面的步骤不用执行
- 检测PPP是否开启:
- cat /dev/ppp
- 开启成功的标志:cat: /dev/ppp: No such file or directory 或者 cat: /dev/ppp: No such device or address,可以继续
- 安装ppp
- yum install -y ppp
- 安装PPTP
- yum install epel-release
- yum install pptpd
- 安装iptables:
- systemctl stop firewalld
- systemctl mask firewalld
- yum install iptables iptables-services
- systemctl enable iptables
- service iptables start
- service iptables save
- 编辑pptpd.conf:
- vi /etc/pptpd.conf
- 搜索localip,去掉下面字段前面的#,然后保存退出
- localip 192.168.0.1
- remoteip 192.168.0.234-238,192.168.0.245
- #这些是默认的,一般不需要去修改,分配给客户端的ip就是234到238之间,你也可以往大了写,看你的客户端有多少。
- 配置options.pptpd
- vi /etc/ppp/options.pptpd
- 搜索ms-dns,去掉搜索到的两行ms-dns前面的#,并修改为下面的字段
- ms-dns 8.8.8.8 #这是谷歌的
- ms-dns 8.8.4.4
- 配置连接VPN客户端要用到的帐号密码
- vi /etc/ppp/chap-secrets
- 添加一行,按照格式写入你的用户名和密码(用 tab 键分割各参数)
- vpnuser pptpd 密码 *
- 修改内核参数
- vi /etc/sysctl.conf
- 在conf末尾添加下面的代码,使内核支持转发
- net.ipv4.ip_forward=1
- 运行下面的命令使内核修改生效
- sysctl -p
- 这个时候把iptables关闭的话是可以连接VPN了,之所以要把iptables关闭是因为没有开放VPN的端口,客户如果直接连接的话是不允许的。这里还需要设置iptables的转发规则,让你的客户端连接上之后能访问外网。
- iptables -A INPUT -p tcp --dport 1723 -j ACCEPT
- iptables -I INPUT -p tcp --dport 47 -j ACCEPT
- #iptables -A INPUT -p 47 -j ACCEPT
- #iptables -A OUTPUT -p 47 -j ACCEPT
- iptables -I INPUT -p gre -j ACCEPT
- iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE
- 注:eth0 为外网网卡
- iptables -A INPUT -i ppp+ -j ACCEPT
- iptables -A OUTPUT -o ppp+ -j ACCEPT
- iptables -F FORWARD
- iptables -A FORWARD -j ACCEPT
- iptables -A POSTROUTING -t nat -o eth1 -j MASQUERADE
- iptables -A POSTROUTING -t nat -o ppp+ -j MASQUERADE
- 注:eth0 为外网网卡
- service iptables save
- 保险起见,到了这里应该重启一下pptpd服务和iptables服务生效。
- systemctl restart iptables
- systemctl restart pptpd
- systemctl enable pptpd.service
- 在 windows 8.1 创建VPN连接:
- 网络和共享中心 -> 设置新的连接或网络 -> 连接到工作区 -> 使用我的internet 连接(VPN) -> 输入服务器IP地址
- 在Ubuntu创建VPN连接时需要勾选“使用点到点加密(MPPE)”,并检查ufw防火墙设置
- sudo tail -f /var/log/ufw.log
- sudo vi /etc/ufw/before.rules
- 找到 # drop INVALID packets ...
- 在下面添加:
- -A ufw-before-input -p 47 -j ACCEPT
- sudo systemctl restart ufw
- 在Fedora创建VPN连接时需要勾选“使用点到点加密(MPPE)”,并检查firewalld防火墙设置
CentOS 7 搭建 VPN 服务
来源: http://www.bubuko.com/infodetail-2347386.html