Selective Routing For VPN in VGHKS

因為工作的地方有一些網路的限制,之前都是用 SSH tunnel 來瀏覽一些被封鎖的內容,但因為最近要搬家的緣故,所以家裡電腦的 SSH tunnel 暫時沒辦法工作,只好改用 ASUS RT-N16 內建的 VPN 來應急。

在 Windows 下,VPN 會把所有的流量導過去,但 Mac 有個「透過 VPN 連線傳送所有流量」的選項可以控制,而且預設是不打開的,如果要方便起見,比照 Windows 下全部導過去也可以,但會損耗掉一些不必要的流量浪費,最大的問題在於,自己區域網路(工作)裡的站也全部不能連,所以還是得想辦法建立一個 white list 比較好。

查了一些方法,似乎無法像 SSH tunnel 那樣可以透過 hostname 搭配萬用字元來過濾,只能從很底層的 routing table 來導流,自動化的機制便是 /etc/ppp/ip-up 這個 script,它會在連線建立後被 hook 執行。

根據目前被封鎖的幾個網站,可列出下列 routes

#!/bin/bash
#
# Script which handles the routing issues as necessary for pppd
# Only the link to Newman requires this handling.
#
# When the ppp link comes up, this script is called with the following
# parameters
#       $1      the interface name used by pppd (e.g. ppp3)
#       $2      the tty device name
#       $3      the tty device speed
#       $4      the local IP address for the interface
#       $5      the remote IP address
#       $6      the parameter specified by the 'ipparam' option to pppd
#

# facebook
/sbin/route add -net 23.59 -interface $1        # fbcdn-sphotos-c-a.akamaihd.net
/sbin/route add -net 23.61 -interface $1        # fbcdn-sphotos-c-a.akamaihd.net
/sbin/route add -net 23.65 -interface $1        # fbcdn-sphotos-b-a.akamaihd.net
/sbin/route add -net 31.13 -interface $1        # star.c10r.facebook.com
/sbin/route add -net 46.33 -interface $1        # fbcdn-sphotos-d-a.akamaihd.net
/sbin/route add -net 66.220 -interface $1       # www.facebook.com
/sbin/route add -net 69.171 -interface $1       #
/sbin/route add -net 72.246 -interface $1       # fbcdn-profile-a.akamaihd.net
/sbin/route add -net 122.56 -interface $1       # fbstatic-a.akamaihd.net
/sbin/route add -net 125.56 -interface $1       # fbstatic-a.akamaihd.net
/sbin/route add -net 163.28 -interface $1       # fbcdn-sphotos-c-a.akamaihd.net
/sbin/route add -net 173.252 -interface $1      # facebook.com
/sbin/route add -net 184.27 -interface $1       # fbcdn-sphotos-f-a.akamaihd.net
/sbin/route add -net 184.51 -interface $1       # fbexternal-a.akamaihd.net
/sbin/route add -net 203.133.9 -interface $1    # fbexternal-a.akamaihd.net

# twitter
/sbin/route add -net 199.59 -interface $1       # twitter.com
                                                # t.co

# wretch
/sbin/route add -net 203.84.197 -interface $1   # www.wretch.cc
/sbin/route add -net 203.188.204 -interface $1  # tw.m.wretch.yahoo.com
/sbin/route add -net 119.160.246 -interface $1  # tw.m.wretch.yahoo.com

初步看來,就是 facebook 的最難搞,每次查出來的 ip 都不夠完整,所以只好之後再動態補完了。

如果要單純化一些,也可以全部導流,再把 VGHKS 區網內的 ip 設成 black list,不過這樣就避免不了浪費流量的問題了,在還不清楚有沒有單日流量上限的前提下,還是麻煩一些吧!


Leave a Reply