1.先看看你的主機是否支持pptp,返回結(jié)果為yes就表示通過。愛掏網(wǎng) - it200.com
?
modprobe ppp-compress-18 && echo yes |
2 .是否開啟了TUN,有的虛擬機主機需要開啟,返回結(jié)果為cat: /dev/net/tun: File descriptor in bad state。愛掏網(wǎng) - it200.com就表示通過。愛掏網(wǎng) - it200.com
?
cat /dev/net/tun |
3.安裝ppp , pptpd 和 iptables。愛掏網(wǎng) - it200.com
a.安裝ppp和pptpd
?
yum -y install ppp pptpd |
b.安裝iptables。愛掏網(wǎng) - it200.com這是自帶的,如果沒有的話就安裝。愛掏網(wǎng) - it200.com
?
yum -y??install iptables |
4.配置pptpd.conf。愛掏網(wǎng) - it200.com
?
vi /etc/pptpd.conf????#找到localip localip 172.16.195.1 remoteip 172.16.195.101-200 #Localip這行是給vpn服務(wù)器設(shè)置一個隧道ip #Remoteip是自動分配給客戶端的ip地址范圍。愛掏網(wǎng) - it200.com |
5.配置options.pptpd
?
vi /etc/ppp/options.pptpd??????#在末尾添加dns #先去掉debug前面的#,開啟日志記錄 ms-dns??8.8.8.8?????? #這是谷歌的,你也可以改成阿里巴巴的或者其它 ms-dns??8.8.4.4 logfile /var/log/pptpd.log |
6.配置連接VPN客戶端要用到的帳號密碼。愛掏網(wǎng) - it200.com
?
vi /etc/ppp/chap-secrets????#格式很通俗易懂。愛掏網(wǎng) - it200.com #?? client為帳號,server是pptpd服務(wù),secret是密碼,*表示是分配任意的ip # Secrets for authentication using CHAP # client????????server???? secret??????????????????IP addresses ??user??????????pptpd????????pwd??????????????????????* |
7.配置sysctl.conf
?
vi /etc/sysctl.conf #添加一行????net.ipv4.ip_forward = 1????#到末尾即可,然后保存,這個很重要,系統(tǒng)路由模式功能。愛掏網(wǎng) - it200.com sysctl -p????#運行這個命令會輸出上面添加的那一行信息,意思是使內(nèi)核修改生效 |
8.這個時候把iptables關(guān)閉的話是可以連接VPN了,之所以要把iptables關(guān)閉是因為沒有開放VPN的端口?客戶如果直接連接的話是不允許的。愛掏網(wǎng) - it200.com這里還需要設(shè)置iptables的轉(zhuǎn)發(fā)規(guī)則,讓你的客戶端連接上之后能訪問外網(wǎng)。愛掏網(wǎng) - it200.com
?
/sbin/iptables -t nat -A POSTROUTING -s 172.16.195.0/24 -o eth0 -j SNAT --to-source 10.175.249.241 /sbin/iptables -t nat -A POSTROUTING -s 10.175.249.0/24 -o eth1 -j SNAT --to-source 58.96.183.250 /sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE |
目標網(wǎng)絡(luò)vpn的內(nèi)部網(wǎng)絡(luò)為10.175.249.0/24,vpn服務(wù)器有2個網(wǎng)卡,其中一個網(wǎng)卡連私有網(wǎng)絡(luò)(eth0),ip是10.175.249.241,另外一個連接公網(wǎng)(eth1),ip地址是58.96.183.250。愛掏網(wǎng) - it200.com這樣就能正常地路由所涉及的網(wǎng)絡(luò)了。愛掏網(wǎng) - it200.com
9.這個時候還是連接不上的,因為iptables把客戶的VPN連接攔截了,不允許連接,所以得開放相應的端口。愛掏網(wǎng) - it200.com
具體是哪個端口可以自己查下,我的是默認的,如果你沒有更改過的話也會是默認的。愛掏網(wǎng) - it200.com
?
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 |
10.保險起見,到了這里應該重啟一下pptpd服務(wù)和iptables服務(wù)生效。愛掏網(wǎng) - it200.com
?
systemctl restart iptables systemctl restart pptpd |
11.VPN服務(wù)器搭建完成。愛掏網(wǎng) - it200.com