在开源固件openwrt路由器建立pptp(vpn)连接

pptp是vpn里其中一种协议,和其它种类的vpn比较可以看这里
http://www.ivpn.net/knowledgebase/62/PPTP-vs-L2TP-vs-OpenVPN.html
其实它是最容易被封锁的,加密也是最弱的(PPTP uses TCP port 1723 and GRE (Protocol 47). PPTP can be easily blocked by restricting the GRE protocol.)。但是可能是用的人少吧,GFW却没有对pptp进行监控。

安装pptp客户端,可以看这里http://wiki.openwrt.org/doc/howto/vpn.client.pptp

重点是配置防火墙区域设置,我的路由器配置为路由模式

见图

这样设置以后,直接在页面里点pptp-vpn哪个网卡的连接就可以了,并且会以远程服务器做为新的网关。但是断开连接以后会有个小问题,就是路由表没有恢复到原来连接前的状态,连默认网关也没有,所以上不了网。这里有个简单的办法。
首先在启动项里输入


# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
echo `route | grep 'default' | awk '{print $2}'`>/tmp/GW
exit


把默认网关保存到了/tmp/GW下,然后利用hotplug
http://wiki.openwrt.org/doc/techref/hotplug


root@OpenWrt:/etc/hotplug.d/iface# cat 99-pptp

#!/bin/sh
[ "$ACTION" = "ifdown" -a "$INTERFACE" = "vpn" ] && {
        gw=`cat /tmp/GW`
        route add default gw ${gw}
        route del xxx.3322.org
        }

这样就解决了。

非常方便的在页面上点“连接”建立pptp vpn,并自动切换默认网关,断开连接也能恢复正常的路由表及默认网关了。


没有评论:

发表评论