歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> centOS7.0 VPN 搭建

centOS7.0 VPN 搭建

日期:2017/3/1 12:21:18   编辑:關於Linux
CentOS7.0 之前采用的是iptables防火牆,而7.0之後默認采用的是firewalld,在VPN設置上也有所不同: 1.檢測是否支持pptpd: modprobe ppp-compress-18 && echo yes 返回yes則表示支持 2.檢測是否開啟tun: cat /dev/net/tun 如果返回cat: /dev/net/tun: File descriptor in bad state 表示支持,否則則需要手動開啟 3.安裝pptpd和ppp: yum -y install ppp pptpd 注:如果提示找不到pptpd 則需要手動下載: rpm -i http://poptop.sourceforge.net/yum/stable/rhel7/pptp-release-current.noarch.rpm 4.配置pptpd.conf : vim /etc/pptpd.conf , 把 localip 192.168.0.1 和 remoteip 192.168.0.234-238,192.168.0.245去掉注釋, romoteip 是開放的終端內網網段,234-245之間任意選擇,即便終端局域網IP是192.168.0.234也不會沖突。 5.修改DNS:vim /etc/ppp/options.pptpd 在末尾添加DNS,google的是主: ms-dns 8.8.8.8 副:ms-dns 8.8.4.4 大家可以在網上搜索一些國外的DNS,自己ping一下,看看哪一個快就是用哪一個。 6.添加賬戶:vim /etc/ppp/chap-secrets #client serversecret IP address 賬號 pptpd 密碼 * *表示分配的任意IP 7.配置sysctl.conf: vim /etc/sysctl.conf ,在末尾添加一行 net.ipv4.ip_forward = 1 ,保存, 然後使用 sysctl -p 使內核修改生效。 8.設置轉發規則: 如果使用了iptables(注意關閉firewalld), 則是: iptables -t nat -A POSTROUTING -s 192.168.0.234/24 -o eth0 -j MASQUERADE 其中,192.168.0.234/24 對應 pptpd.conf 中的 remoteip iptables -F -t nat iptables -X -t nat iptables -Z -t nat 如果要清空轉發規則,可以使用上面的命令 然後使用 service iptables save,注意:如果是7.0,重啟之後就會轉發規則失效,需要寫入rc.local 如下所示: chmod +x /etc/rc.d/rc.local vim /etc/rc.d/rc.local 將轉發規則追加到最後保存退出。 開放VPN端口: iptables -I INPUT -p tcp --dport 1723 -j ACCEPT iptables -I INPUT -p tcp --dport 47 -j ACCEPT iptables -I INPUT -p gre -j ACCEPT 重啟pptpd ,service pptpd restart 如果使用firewalld,則是 : firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -i eth0 -p tcp --dport 1723 -j ACCEPT firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p gre -j ACCEPT firewall-cmd --permanent --direct --add-rule ipv4 filter POSTROUTING 0 -t nat -o eth0 -j MASQUERADE firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i ppp+ -o eth0 -j ACCEPT firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i eth0 -o ppp+ -j ACCEPT 重啟防火牆 firewall-cmd --reload 10.設置開啟自啟動: chkconfig pptpd on 大概就是這麼一個過程,本人在前兩年就想探索linux,但由於時間一直安排不過來,就一直擱置了,最近有空就看看,算是剛接觸linux的,對於上面的內容,純屬是本人在網上找的資料和實踐的結果,並沒有權威一說,可能有很多錯誤的地方,望大神們不吝賜教,小墨十分感謝。
Copyright © Linux教程網 All Rights Reserved