买了一个Apple TV3,因为香港区默认是不支持Netflix的,所以除了要用美国区的帐户登录之外,还需要让Apple的服务器看到访问的Source IP是美国的,
因此不为翻墙,而是为了SNAT,我又要配置一下VPN了,同时因为不在墙内,也不需要chnroutes之类的了,但是要Source based routing或者Multiple routing table,好让除了ATV之外的所有设备都不走VPN,
然后我想起秋香同学 @fqx 写过教程哦,然后我看了秋香同学的教程,然后我发现秋香的教程,实在是…
我还是写个清楚一点的吧,免得其他同学像我一样照着做却还要自己troubleshooting!
先决条件当然是有一台支持Tomato firmware的路由器,路由器上有足够的空间,或者加了个U盘,有VPN Server,有帐号,有密码,有一顆愛折腾的心神马的,然后:
1)刷一个有tun.ko的Tomato版本,同樣建議用shibby mod,選擇支持VPN的就好
http://tomato.groov.pl/?page_id=164
2)U盘格式化成EXT3或者FAT32或者NTFS插上去,配置把U盘挂载到/opt目录
首先登录到Tomato的管理界面,然后在USB and NAS » USB Support下勾选以下选项:
“Core USB Support” / “USB 2.0 Support” / “USB Storage Support” / “File Systems Support”(全选) / “Automount”
然后到“Administration » Scripts » Init”,把以下內容帖进去,
echo "LABEL=optware /opt ext3 defaults 1 1" >> /etc/fstab
sleep 2
insmod /lib/modules/2.6.22.19/kernel/drivers/net/tun.ko
保存,重启路由器
3) 配置軟件repository,
cd /opt
mkdir /tmp/harddisk/opt
wget http://wl500g-repo.googlecode.com/svn/ipkg/entware_install.sh
chmod +x ./entware_install.sh
./entware_install.sh
4) 安裝VPNC
opkg update
opkg install vpnc
安裝完之後可能会有vpnc-script不存在的问题,可以手动下载一下
cd /opt/sbin/
wget http://git.infradead.org/users/dwmw2/vpnc-scripts.git/blob_plain/HEAD:/vpnc-script
chmod +x vpnc-script
5)配置VPNC和vpncwatch
先下載vpncwatch,詳細可參考P大文章 vpncwatch 修正(外)
cd /opt/sbin
wget http://p5.gfw.io/paveo/vpncwatch
好吧,VPNC配置直接看P大 @Paveo 的教程吧,我也懒得写了,(写这个期间我从墙外撞墙被reset了,好,很好,非常好)
6)配置多路由表,
除了秋香同学那个不好的参考 A Bridge To Home Theater (2) 之外,好的参考在这里:
http://linux-ip.net/html/routing-tables.html
(看人家写得多好多清晰啊,秋香你真的要惭愧一下!)
傻瓜教程,
新建/opt/etc/vpnc/iproute2文件,貼入以下內容:
#!/bin/sh
mkdir /etc/iproute2
cp rt_tables /etc/iproute2/rt_tables
ip rule add from table novpn //这里可以逐个主机的写,也可以用掩码整段配置
ip route add $(nvram get wan_gateway_get) dev proto kernel scope link src $(nvram get wan_ipaddr) table novpn //是获得外网IP地址的接口,也许是ppp0,也许是vlan2,自己确认一下吧
ip route add dev br0 proto kernel scope link src table novpn //是内网的子网和掩码,例如192.168.1.0/24,是路由器的内网IP地址,例如192.168.1.1
ip route add default via $(nvram get wan_gateway_get) dev table novpn //是获得外网IP地址的接口,也许是ppp0,也许是vlan2,自己确认一下吧
ip route flush cache
編輯完之後別忘了執行權限
chmod +x /opt/etc/vpnc/iproute2
新建/opt/etc/vpnc/rt_tables文件,貼入以下內容:
255 local
254 main
253 default
200 novpn
0 unspec
然后到“Administration » Scripts » WAN up”,把以下內容帖进去,
#IPsec VPN Setting
vpncwatch -c twitter.com -p 80 -i 10 vpnc
sleep 10
service dnsmasq restart
#Multiple Routing Table
/opt/etc/vpnc/iproute2
嗯,打完收工!