在 Vultr VPS 中 以 Debian 8 i386 (jessie) 為 作業系統 平台 手動 搭建 PPTP VPN 全過程,vultrvps
補救伺服器並安裝 PPTP 服務
apt-get update
apt-get upgrade
apt-get install pptpd
編輯 /etc/pptpd.conf
找到 #localip 以及 #remoteip 行,刪除#並設定 ip 地址
localip 172.16.31.254
remoteip 172.16.31.234-238
編輯 /etc/sysctl.conf
去掉 #net.ipv4.ip_forward=1 的#號,開啟ipv4 forward
修改完成後執行 sysctl -p
編輯 /etc/ppp/pptpd-options
修改dns伺服器位址
ms-dns 8.8.8.8
ms-dns 8.8.4.4
編輯 /etc/ppp/chap-secrets
添加 PPTP 帳號
[注
格式為:
username1 pptpd password *
username2 pptpd password 172.16.31.234
第一列是使用者名稱,第二列是伺服器名(預設 pptpd ,注意和 /etc/ppp/pptpd-options 檔案中 name 行的值保持一致)
第三列是密碼,第四列是 IP 限制(不限制用 * 表示)
第一行格式為不固定用戶端ip地址,第二行格式為固定用戶端ip地址
]
使用 iptables 來建立 NAT
安裝iptables apt-get install iptables
向 nat 表中加入一條規則
iptables -t nat -A POSTROUTING -s 172.16.31.0/24 -o eth0 -j MASQUERADE
[注
eth0是網卡名字,可以通過命令 ifconfig 查看得到
]
設定 MTU
iptables -I FORWARD -p tcp --syn -i ppp+ -j TCPMSS --set-mss 1356
[注
Vultr 建議
Note: We recommend configuring a MTU of 1450 on your private network. Using a larger MTU will result in poor performance.
]
iptables 的規則會在下次重啟時被清除,為防止重啟機器後iptables丟失,運行
iptables-save > /etc/iptables-rules
編輯 /etc/network/interfaces 檔案
找到 eth0 那一節,在對 eth0 的設定最末尾加上下面這句:
pre-up iptables-restore < /etc/iptables-rules
這樣當網卡 eth0 被載入的時候就會自動載入我們預先用 iptables-save 儲存下的配置。
重啟 PPTP 服務
/etc/init.d/pptpd restart
編輯 /etc/rc.local
添加開機啟動
/etc/init.d/pptpd restart
特此感謝大牛們提供的思路與代碼!
參考博文,不分先後:
Debian搭建vpn - 時光旅行的懶貓 - 部落格園
Debian搭建VPN - 麥田守望者
Debian PPTP VPN 配置教程 - reizhi