服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > 开发教程 > linux教程 >

Centos 7 配置PPTP VPN攻略

时间:2016-10-16 19:43来源:未知 作者:最模板编辑 点击:
准备工作: 1、一台centos7主机,内网ip 192.*.*.* 2、一个连接外网的路由器,外网固定ip 210.*.*.* DNS 210.*.*.* 开始安装: 1、更新centos7主机 yum update �y reboot #重启 2、检测系统环境 modprobe
准备工作:
 
1、一台centos7主机,内网ip 192.*.*.*
 
2、一个连接外网的路由器,外网固定ip 210.*.*.*  DNS 210.*.*.*
 
 
 
开始安装:
 
1、更新centos7主机
 
yum update �y
reboot #重启
2、检测系统环境
 
modprobe ppp-compress-18 && echo success
显示success说明系统支持MPPE补丁,如果不支持,需要先安装kernel-devel
 
# yum install kernel-devel
 
检查系统是否开启TUN/TAP支持
 
cat /dev/net/tun
显示结果为下面的文本,则表明通过:
 
cat:/dev/net/tun: File descriptor in bad state
 
检查系统是否开启ppp支持
 
cat /dev/ppp
显示结果为下面的文本,则表明通过:
 
cat:/dev/ppp: No such device or address
 
上面三条必须同时满足,否则不能安装pptp vpn
 
 
 
3、关闭SELINUX
 
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
setenforce 0 #使配置立即生效
4、更新epel(参考 http://mannerwang.blog.51cto.com/12009183/1852806)
 
yum makecache #更新yum缓存
yum repolist #查看yum源,会多一个epel源
5、安装iptables、ppp、pptpd
 
yum install -y ppp iptables pptpd
6、配置pptp参数
 
vi /etc/ppp/options.pptpd
找到 ms-dns两行,将注释#去掉,并改为如下
 
ms-dns 210.*.*.*(公司外网DNS、可以使用114、8等通用DNS)
 
ms-dns 8.8.8.8
 
 
 
7、设置pptp拨号用户和密码(可以设置多个用户,每行一个)
 
vi /etc/ppp/chap-secrets
#client          server   secret                   IP addresses
vpntest          pptpd    123456                   *
*表示为客户端自动分配IP地址
 
8、设置pptp服务器IP地址,设置vpn拨入客户端ip地址池
 
vi /etc/pptpd.conf
localip 172.16.36.1  #设置pptp虚拟拨号服务器IP地址(注意:不是服务器本身的IP地址)
remoteip 172.16.36.2-254  #为拨入vpn的用户动态分配IP地址
这里有个坑是最后一行需要为空内容,原因目前未知..
 
9、启动服务
 
systemctl start pptpd.service #启动pptp
systemctl status pptpd.service #查看pptp状态
systemctl enable pptpd.service #设置开机启动
10、修改内核转发参数
 
vi /etc/sysctl.conf  #编辑
net.ipv4.ip_forward = 1  #设置为1
/sbin/sysctl -p  #使设置立刻生效
11、修改防火墙规则---重点内容
 
systemctl start iptables.service #启动防火墙
开机启动:chkconfig iptables on
 
编辑配置文件,以下为我的配置,请自行对比默认配置参考
 
主要是添加1723端口和gre协议.不推荐SHELL运行,建议直接编辑配置文件
 
vi /etc/sysconfig/iptables  
#sample configuration for iptables service
#you can edit this manually or use system-config-firewall
#please do not ask us to add additional ports/services to this defaultconfiguration
 
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
 
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 22 -jACCEPT
-A INPUT -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 1723 -jACCEPT
-A INPUT -p gre -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i ppp+ -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m state --state INVALID -j DROP
-A OUTPUT -m state --state INVALID -j DROP
 
COMMIT
#completed on 2016-9-18 15:33:54
 
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A POSTROUTING -s 172.16.36.0/24 -o eno16777984 -j MASQUERADE
COMMIT
#completed on 2016-9-18 15:33:54
由于centos7中的iptables规则重启失效,添加到local文件中
 
vi /etc/rc.d/rc.local #在文件末尾添加此行代码
 
iptables -t nat -A POSTROUTING -s 172.16.36.0/24 -o eno16777984 -j MASQUERADE
上面有2处需要注意,两个POSTROUTING字段都使用了本机的网卡名称,其中eno16777984是虚拟主机网卡,而不是传统上的eth0,务必注意!
 
 
 
重启iptables使得规则生效
 
systemctl restart iptables.service
 
 
 
查看路由表及iptables规则
 
iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  172.16.36.0/24       anywhere
iptables -t filter -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere             state NEW,RELATED,ESTABLISHED tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere             state NEW,RELATED,ESTABLISHED tcp dpt:pptp
ACCEPT     gre  --  anywhere             anywhere             state NEW,RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             state NEW,RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
DROP       all  --  anywhere             anywhere             state INVALID
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere             state INVALID
坑点又来了,iptables启动时默认是不加载模块的,这样就会导致连接时报619无法验证密码的错误
 
加载iptables模块
 
modprobeip_nat_pptp
modprobeip_conntrack_pptp
查看模块是否加载
 
lsmod|grep pptp
nf_nat_pptp            13115  0
nf_nat_proto_gre       13009 1 nf_nat_pptp
nf_conntrack_pptp      19257 1 nf_nat_pptp
nf_conntrack_proto_gre    14287 1 nf_conntrack_pptp
nf_nat                 26146  4nf_nat_proto_gre,nf_nat_ipv4,nf_nat_pptp,nf_nat_masquerade_ipv4
nf_conntrack          105745  8nf_conntrack_proto_gre,nf_nat,nf_nat_ipv4,nf_nat_pptp,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_ipv4,nf_conntrack_pptp
如果想让iptables自动加载以上模块,可以编辑
 
vi /etc/sysconfig/iptables-config
在IPTABLES_MODULES=""字段中添加以上模块。
 
IPTABLES_MODULES="ip_nat_pptp ip_nat_proto_gre"
 
重启iptables即可
 
 
 
12、安装net-tools,查看1723端口
 
yuminstall -y net-tools
netstat -nap | grep 1723 | grep pptpd
tcp        0      0 0.0.0.0:1723            0.0.0.0:*               LISTEN      1070/pptpd
13、在路由器侧配置端口及外网ip,这个要看各自的路由本身的操作了,可能还需要配置路由表,将172.16.36.0加到表中.
 
 
 
查看pptp服务状态
 
systemctl status pptpd.service
 
systemctl status iptables.service
 
 
 
要保证的服务:
 
pptpd可以自启动
 
iptables可以自启动并加载转发、gre模块
 
 
 
经过如上一系列操作,系统PPTP搭建成功,且重启后服务即刻启动。
 
 
 
通信分析:
 
外网用户通过210 的PPTP外网映射ip及账号密码默认端口访问到内网192 PPTP主机并获得172 的IP
 
访问内网页面时,192的请求指向172 VPN并由内网PPTP主机将172 IP nat到内网192 并返回数据,实现VPN的功能,,,也不知道我说得对不对
 
 
 
Q&A:
 
1、为什么选择pptp而不是openvpn?因为后者还没研究成果...
 
2、关于吞吐量、关于安全---目前还在研究,包括iptables的规则也需要细化
 
3、PPTP支持同一用户多地重复连接
 
4、连接多个不同VPN时是否有安全隐患--一般没有,可以设置路由表对网络通信进行区分
 
 
 
本文参考了如下作者内容,表示感谢!
 
http://www.wanghailin.cn/centos-7-vpn/
 
http://www.osyunwei.com/archives/7407.html
 
http://www.111cn.net/sys/linux/86641.htm
 
http://www.centoscn.com/image-text/install/2014/1201/4211.html
 
http://www.tuicool.com/articles/uu6NJb
 
 
 
(完)
(责任编辑:最模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容