更新服務器并安裝PPTP服務
apt-getupdate
apt-getupgrade
apt-getinstallpptpd
編輯 /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 賬號
[注
格式為:
username1pptpdpassWord*
username2pptpdpassword172.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
新聞熱點
疑難解答