
1、檢查系統內核是否支持MPPE
modprobe ppp-compress-18 && echo OK
顯示OK說明系統支持MPPE
2、檢查系統是否開啟TUN/TAP支持
cat /dev/net/tun
cat: /dev/net/tun: 文件描述符處于錯誤狀態
如果這條指令顯示結果為下面的文本,則表明通過
3、 檢查PPP是否支持MPPE
strings ‘/usr/sbin/pppd’|grep -i mppe|wc -l
43如果以上命令輸出為“0”則表示不支持;輸出為“30”或更大的數字就表示支持.
4、安裝ppp和iptables????? #PPTP需要這兩個軟件包,一般centOS自帶
yum install -y ppp iptables
5、安裝PPTP
yum install epel-release
yum install pptpd
6、配置PPTP
(1)vi /etc/ppp/options.pptpd #編輯,保存
name pptpd?? ??? ??? ???????????? #自行設定的VPN服務器的名字,可以任意
#refuse-pap?? ??? ??? ??? ?????? ? #拒絕pap身份驗證
#refuse-chap?? ??? ??? ? ? ? ? ?? #拒絕chap身份驗證
#refuse-mschap?? ??? ??? ????? #拒絕mschap身份驗證
require-mschap-v2?? ??? ????? #為了最高的安全性,我們使用mschap-v2身份驗證方法
require-mppe-128?? ??? ? ? ?? #使用128位MPPE加密
ms-dns 8.8.8.8?? ??? ??? ??????? #設置DNS
ms-dns 8.8.4.4
proxyarp?? ??? ??? ?? ? ? ? ? ? ? ? #啟用ARP代理,如果分配給客戶端的IP與內網卡同一個子網
#debug?? ??? ??? ??? ??? ?????????? #關閉debug
lock
nobsdcomp
novj
novjccomp
#nologfd??????????????????????????? #不輸入運行信息到stderr
logfile /var/log/pptpd.log ?? #存放pptpd服務運行的的日志
(2)vi /etc/ppp/chap-secrets #編輯,保存
kuaile pptpd 666666 * ? ? ? ? ? ? ? ? #設置用戶名:test 密碼:123456
或者
vpnuser add kuaile 666666
(3)vi /etc/pptpd.conf #編輯,保存
option /etc/ppp/options.pptpd
logwtmp
localip 10.0.6.1?? ??? ? ? ? ? ? ? ? ? #設置VPN服務器虛擬IP地址
remoteip 10.0.6.101-200?? ??? ?#為撥入VPN的用戶動態分配10.0.6.101~10.0.0.200之間的IP
7. 開啟系統路由模式
sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0
vi /etc/sysctl.conf ? ? ? ? ? ? ? ? #編輯
net.ipv4.ip_forward = 1 ? ? ? #找到此行 去點前面#,把0改成1 開啟路由模式,如果沒有就自行添加
/sbin/sysctl -p?? ??? ??? ? ? ? ? ?? #使設置立刻生效
sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
7、配置防火墻NAT轉發
centos 7 默認采用firewalld動態防火墻,我還是更習慣使用iptables
yum install iptables-services
systemctl stop firewalld.service
systemctl disable firewalld.service
yum erase firewalld
systemctl enable iptables.service
systemctl start iptables.servic
開啟包轉發
iptables -t nat -A POSTROUTING -s 10.0.6.0/24 -o eth0 -j MASQUERADE
意思是對即將發送出去的數據包進行修改,對來自設備eth0且源地址是10.0.6.0/24的數據包,把源地址修改為主機地址及vPN地址
iptables -t nat -L???????????????????? #完成后可以查看NAT表是否已經生效
這里要注意服務器的網口不一定是eth0,用netstat -i 查看
service iptables save??? #保存防火墻設置
service? restart????????????? #重啟防火墻
對于開啟了iptables過濾的主機,需要開放VPN服務的端口:1723 和gre協議
使用一下命令添加
開放pptp使用的1723端口和gre協議
iptables -A INPUT -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 1723 -j ACCEPT iptables -A INPUT -p gre -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.0.6.0/24 -o eth0 -j MASQUERADE
或者(這倆條應該是等效的,一種不行的話, 用另一種試試)
iptables -t nat -A POSTROUTING -s 10.0.6.0/24 -o eth0 -j SNAT –to 你的主機IP
iptables -A FORWARD -i ppp+ -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
##############################################################################################################################
如果iptables規則中有拒絕的選項,需要注意接受的要在拒絕的前面。
Centos 7 的iptables默認規則中就有
-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibited添加的規則一定要在這條規則的前面,所以用插入的方法添加規則
iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 1723 -j ACCEPTiptables -I INPUT 6 -p tcp -m state --state NEW -m tcp --dport 47 -j ACCEPTiptables -I INPUT 7 -p gre -m state --state NEW -j ACCEPTiptables -I FORWARD 2 -i ppp+ -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT iptables -I FORWARD 3 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.0.6.0/24 -o eth0 -j MASQUERADE
添加完成后試用iptalbes命令檢查一下
[root@Centos7 ~]# iptables -LChain INPUT (policy ACCEPT)target???? prot opt source?????????????? destinationDROP?????? all? --? anywhere???????????? anywhere??????????? state INVALIDACCEPT???? icmp --? anywhere???????????? anywhereACCEPT???? all? --? anywhere???????????? anywhereACCEPT???? tcp? --? anywhere???????????? anywhere??????????? state NEW,RELATED,ESTABLISHED tcp dpt:sshACCEPT???? tcp? --? anywhere???????????? anywhere??????????? state NEW,RELATED,ESTABLISHED tcp dpt:pptpACCEPT???? gre? --? anywhere???????????? anywhere??????????? state NEW,RELATED,ESTABLISHEDACCEPT???? all? --? anywhere???????????? anywhere??????????? state RELATED,ESTABLISHEDREJECT???? all? --? anywhere???????????? anywhere??????????? reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT)target???? prot opt source?????????????? destinationDROP?????? all? --? anywhere???????????? anywhere??????????? state INVALIDACCEPT???? all? --? anywhere???????????? anywhere??????????? state NEW,RELATED,ESTABLISHEDACCEPT???? all? --? anywhere???????????? anywhere??????????? state RELATED,ESTABLISHEDREJECT???? all? --? anywhere???????????? anywhere??????????? reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT)target???? prot opt source?????????????? destinationDROP?????? all? --? anywhere???????????? anywhere??????????? state INVALID
[root@Centos7 ~]# iptables -t nat -LChain PREROUTING (policy ACCEPT)target???? prot opt source?????????????? destinationChain POSTROUTING (policy ACCEPT)target???? prot opt source?????????????? destinationMASQUERADE? all? --? 10.0.6.0/24????????? anywhereChain OUTPUT (policy ACCEPT)target???? prot opt source?????????????? destination
沒問題后可以保存一下
service iptables save
這是我設置iptables的全部命令,供參考
888是我修改的ssh端口號
/sbin/iptables -F /sbin/iptables -Z /sbin/iptables -P INPUT ACCEPT /sbin/iptables -A INPUT -m state --state INVALID -j DROP /sbin/iptables -A INPUT -p icmp -j ACCEPT /sbin/iptables -A INPUT -i lo -j ACCEPT /sbin/iptables -A INPUT -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 888 -j ACCEPT /sbin/iptables -A INPUT -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 1723 -j ACCEPT /sbin/iptables -A INPUT -p gre -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT /sbin/iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT /sbin/iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited /sbin/iptables -P FORWARD ACCEPT /sbin/iptables -A FORWARD -m state --state INVALID -j DROP /sbin/iptables -A FORWARD -i ppp+ -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT /sbin/iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT /sbin/iptables -A FORWARD -j REJECT --reject-with icmp-host-prohibited /sbin/iptables -P OUTPUT ACCEPT /sbin/iptables -A OUTPUT -m state --state INVALID -j DROP /sbin/iptables -F -t nat /sbin/iptables -Z -t nat /sbin/iptables -t nat -A POSTROUTING -s 10.0.6.0/24 -o seth0 -j MASQUERADE
這是我的iptabls規則文件
[root@Centos7 ~]# cat /etc/sysconfig/iptables# Generated by iptables-save v1.4.7 on Fri Nov 28 15:27:36 2014*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [67:9660]-A INPUT -m state --state INVALID -j DROP-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 888 -j ACCEPT-A INPUT -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 1723 -j ACCEPT-A INPUT -p gre -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -m state --state INVALID -j DROP-A FORWARD -i ppp+ -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT-A FORWARD -j REJECT --reject-with icmp-host-prohibited-A OUTPUT -m state --state INVALID -j DROPCOMMIT# Completed on Fri Nov 28 15:27:36 2014# Generated by iptables-save v1.4.7 on Fri Nov 28 15:27:36 2014*nat:PREROUTING ACCEPT [7:1301]:POSTROUTING ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A POSTROUTING -s 10.0.6.0/24 -o seth0 -j MASQUERADECOMMIT# Completed on Fri Nov 28 15:27:36 2014
8、設置PPTP開機啟動
service pptpd start?? ? ? ? ? ? ? ? ? ? ? ? ? #啟動pptpd
systemctl enabled pptpd ? ??? ? ? ? ? ?? #設置開機啟動
pptpd服務使用的端口是1723,這個端口是系統固定分配的,可以通過查看該端口檢查pptpd服務的運行情況。
命令:netstat -ntpl
[root@Centos7 ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address?????????????? Foreign Address???????????? State?????? PID/Program name
tcp??????? 0????? 0 127.0.0.1:631?????????????? 0.0.0.0:*?????????????????? LISTEN????? 1423/cupsd
tcp??????? 0????? 0 127.0.0.1:25??????????????? 0.0.0.0:*?????????????????? LISTEN????? 1693/master
tcp??????? 0????? 0 0.0.0.0:44666?????????????? 0.0.0.0:*?????????????????? LISTEN????? 1358/rpc.statd
tcp??????? 0????? 0 0.0.0.0:1723??????????????? 0.0.0.0:*?????????????????? LISTEN????? 2020/pptpd
tcp??????? 0????? 0 0.0.0.0:66????????????????? 0.0.0.0:*?????????????????? LISTEN????? 1579/sshd
tcp??????? 0????? 0 0.0.0.0:111???????????????? 0.0.0.0:*?????????????????? LISTEN????? 1310/rpcbind
tcp??????? 0????? 0 ::1:631???????????????????? :::*??????????????????????? LISTEN????? 1423/cupsd
tcp??????? 0????? 0 ::1:25????????????????????? :::*??????????????????????? LISTEN????? 1693/master
tcp??????? 0????? 0 :::66?????????????????????? :::*??????????????????????? LISTEN????? 1579/sshd
tcp??????? 0????? 0 :::33794??????????????????? :::*??????????????????????? LISTEN????? 1358/rpc.statd
tcp??????? 0????? 0 :::111????????????????????? :::*??????????????????????? LISTEN????? 1310/rpcbind
至此,VPN服務器搭建完成.

















