搭建 VPN 服务器的方法非常多,比较著名的有 PPTP, L2TP/IPSec 和OpenVPN。
这三种方式中后两者的安全性比较好,但配置较麻烦。其中 OpenVPN 在 Windows/Mac 平台上还需要额外的客户端。
而L2TP/IPSec 方式虽然比较好,但我配置后,虽然 Windows 和 Linux 用户没有问题,但 Mac/iPhone却始终无法连上,所以暂时删掉了,日后搞清楚是什么问题再换到这种方式。
只剩下 PPTP 了。事实上 PPTP 是这三者中配置最容易的方式,而且由于 Windows/Mac 系统中都内建相应的客户端,使用起来非常方便。
环境:Debian (服务器)单网卡,Win7(客户机)
服务器ip地址:192.168.1.250 ,客户机ip地址:192.168.1.2
VPN-SERVER:~# apt-get pptpd
系统会自动解决依赖关系,安装好后,需要进行一番设置。
编辑 /etc/pptpd.conf
VPN-SERVER:~# nano /etc/pptpd.conf
localip 192.168.15.1
remoteip 10.100.15.2-100
编辑 /etc/ppp/pptpd-options 文件
VPN-SERVER:~# nano etc/ppp/pptpd-options
ms-dns 8.8.8.8
ms-dns 114.114.114.114
修改 /etc/ppp/chap-secrets 文件
这里面存放着 VPN的用户名和密码,根据你的实际情况填写即可。如文件中注释所示,第一列是用户名,第二列是服务器名(默认写 pptpd 即可,如果在
pptpd-options 文件中更改过的话,注意这里保持一致),第三列是密码,第四列是 IP 限制(不做限制写 * 即可)
VPN-SERVER:~# nano /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client server secret IP addresses
username pptpd 123456 *
重启 pptpd 服务使新配置生效
VPN-SERVER:~# /etc/init.d/pptpd restart
首先修改内核设置,使其支持转发功能
修改 /etc/sysctl.conf
VPN-SERVER:~# nano /etc/sysctl.conf
net.ipv4.ip_forward = 1
使设置永久生效
VPN-SERVER:~# cat /proc/sys/net/ipv4/ip_forward
做snat,使vpn拨号进来后可以访问Internet(外网);
VPN-SERVER:~#
nano /root/snat.sh
#/bin/bash
#加载需要的模块
modeprobe iptable_nat
modeprobe ip_conntrack
modeprobe ip_conntrack_ftp
modeprobe ip_nat_ftp
#清除所有用户已经定义的规,自定义链,将所有chain的计数和流量统计为0
iptables -F
iptables -X
iptables -Z
#修改SNAT,用于上外网
iptables -t nat -A POSTROUTING -s 192.168.15.0/24 -j SNAT -- to 192.168.15.1
执行此脚本
VPN-SERVER:~# sh /root/snat.sh
如果服务器采用了shorewall防火墙,需要开放端口1723,47和gre协议
略…
至此,可以设置VPN客户端连接了。