問題
想要在不能使用VPN的產品上透過Wifi連到VPN,就可以解開有些服務的地區限制,也可以以非常便利的方式快速切換VPN。
環境
Unifi USG
解決辦法
首先先在你想要的國家架設OpenVPN伺服器,或是使用免費或付費的OpenVPN伺服器。
取得ovpn檔案後用記事本或你習慣的文字編輯器開啟檔案在<ca>之前加上“route-nopull”
route-nopull #加上
<ca>
xxxxxxxxxxxxx
接下來將ovpn檔案複製到USG,路徑:/config/openvpn/
scp /path/to/filename.ovpn user@usg-ip:/config/openvpn/
之後在Unifi上新增你要使用的Corporate Network(有線網路)&Wireless Network(無線網路)並設定VLANID
如果直接在USG上設定OpenVPN跟路由的話會因為重新啟動而覆蓋掉原本的更動,所以要在Unifi Controller中加上config.gateway.json檔案,內容如下:
{
"firewall": {
"modify": {
"namevpn": {
"rule": {
"10": {
"action": "modify",
"description": "Traffic to VLAN to VPN",
"modify": {
"table": "1"
},
"source": {
"address": "<VLAN's Address/Subnet>"
}
}
}
}
},
"source-validation": "disable"
},
"interfaces": {
"ethernet": {
"eth1": {
"vif": {
"<VLANID>": {
"firewall": {
"in": {
"modify": "namevpn"
}
}
}
}
}
},
"openvpn": {
"vtun0": {
"firewall": {
"in": {
"name": "LAN_IN"
},
"local": {
"name": "LAN_LOCAL"
},
"out": {
"name": "LAN_OUT"
}
},
"config-file": "/config/openvpn/filename.ovpn"
}
}
},
"protocols": {
"static": {
"table": {
"1": {
"interface-route": {
"0.0.0.0/0": {
"next-hop-interface": {
"vtun0": "''"
}
}
}
}
}
}
},
"service": {
"nat": {
"rule": {
"5000": {
"description": "masq to vpn vtun0",
"destination": {
"address": "0.0.0.0/0"
},
"outbound-interface": "vtun0",
"type": "masquerade"
}
}
}
}
}
依照你的Unifi網路設定更改你想要使用的<VLAN’s Address/Subnet>&<VLANID>,之後將config.gateway.json複製到:/unifi/data/sites/<unifi_base>/
scp /path/to/config.gateway.json user@unifi-controller:/unifi/data/sites/<unifi_base>/
<unifi_base>的位置因操作系統而異。你可以在瀏覽器的URL上面,控制器的網址中找到。原始站點名為“default”,如果你有一個以上的站點,Unifi將會為每個創建的站點分配一個隨機字符串。例如,當在站點的儀表板頁面面時,將在URL欄中看到:
https://127.0.0.1:8443/manage/s/ceb1m27d/dashboard
“ceb1m27d”就是<unifi_base>的位置
把檔案丟進去以後你可以去Devices > USG > Config > Manage Device > Force provision,強制Provision USG,就會把你的設定檔推送到USG上,這個過程可能要等待數分鐘。
如果想要恢復的話單純刪除config.gateway.json後強制Provision USG就可以回復原狀了。
以上。