赞
踩
- cat /etc/redhat-release
-
- a)centos版本小于7,安装以下软件
-
- yum -y install ppp pptpd iptables
-
- b)centos版本大于7,还需额外安装一下软件
- <https://www.notion.so/VPN-7fc4d404fa2d4b99b650d2351daa54d8>
- yum update iptables
-
- yum -y install iptables iptables-services
配置pptpd服务
配置pptpd服务ip,取消默认文件localip、remoteip前的#,也可自行设置。主要用于服务地址及客户端地址配置,客户端地址在后面配置防火墙策略至关重要
- vi /etc/pptpd.conf
-
- # (Recommended)
-
- localip 192.168.0.1#(固定写法)
-
- remoteip 192.168.0.100-109,192.168.0.245#(固定写法)
-
- # or
-
- #localip 192.168.0.234-238,192.168.0.245
-
- #remoteip 192.168.1.234-238,192.168.1.245
配置ppp中DNS,增加8.8.8.8、8.8.4.4 GoogleDNS
- vi /etc/ppp/options.pptpd
-
- 修改后(此处只截取了部分)
-
- #ms-dns 10.0.0.1
-
- #ms-dns 10.0.0.2
-
- ms-dns 8.8.8.8
-
- ms-dns 8.8.4.4
配置客户端用户
- vi /etc/ppp/chap-secrets
-
- 修改后,分别为用户名、服务、密码、ip。(ip为 " * " 则代表所有ip均可访问)
-
- # Secrets for authentication using CHAP
-
- # client server secret IP addresses
-
- root pptpd root *
开启内核转发
- #查看内核配置(此处主要作用于修改内核转发)
-
- cat /etc/sysctl.conf
-
- #修改为允许转发(默认=0),如果没有自行添加即可
-
- net.ipv4.ip_forward=1
生效
sysctl -p
配置防火墙策略
- #查看防火墙当前配置
-
- iptables -L -n
-
- #允许所有请i去
-
- iptables -P INPUT ACCEPT
-
- # 清空默认所有规则
-
- iptables -F
-
- # 清空自定义所有规则
-
- iptables -X
-
- # 计数器置0
-
- iptables -Z
-
- # 允许127.0.0.1访问本地服务
-
- iptables -A INPUT -i lo -j ACCEPT
-
- # 允许访问外部服务
-
- iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
-
- # 允许 ping
-
- iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-
- # 开启 ssh 端口
-
- iptables -A INPUT -p tcp --dport 22 -j ACCEPT
-
- # 开启 pptpd 端口
-
- iptables -A INPUT -p tcp --dport 1723 -j ACCEPT
-
- #配置转发策略 192.168.0.* 到 MASQUERADE(会自动判断公网IP)
-
- iptables -A POSTROUTING -t nat -s 192.168.0.0/24 -o eth0 -j MASQUERADE

保存并测试
- #保存iptables配置
-
- service iptables save 或者 /etc/init.d/iptables save
- iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
-
- #重启iptables服务
-
- service iptables restart 或者 /etc/init.d/iptables restart
-
- #重启pptpd服务,如果提示需要restart-kill,执行即可
-
- service pptpd restart 或者 /etc/init.d/pptpd restart
设置开机自启
- # 开机启动 iptables
-
- systemctl enable iptables.service
-
- # 开机启动 pptpd
-
- systemctl enable pptpd.service
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。