網件R7800 openwrt使用v2ray+mkcp+透明代理完美翻牆
本文主要介紹了基於R7800這個基於arm架構處理器的搭建openwrt以及對V2ray的安裝,並適配mkcp與透明代理,其中的v2ray搭建相關理論上所有的openwrt都能夠通用。
首先在路由器的選擇上,網件R7800是整套高通解決方案,相比於R8000、華碩AC88U等,在散熱穩定性等方面有著很大的優勢,為了省事以及一步到位,趁著雙十一我直接入手了R7800。下面我們就開始對R7800開始手術,最終的目標是高可定製,基於kcp協議的穩定翻牆。
順便提一下,這貨還真的大,簡直可以蓋住我整個MBP的鍵盤。
這邊R7800至少目前為止沒有梅林等解決方案,但是其還有各類 ofollow,noindex" target="_blank">其他選擇 ,今天我們就刷入 OpenWrt ,我們可以在 論壇上 看到hnyman為其確實下了很多心血。
I. 刷Openwrt
首先先下載 r7800-openwrt-18.06.1 ,下載完後我們通過以下步驟讓路由器進入刷機模式並準備好刷機:
- 關閉路由器電源
- 按住復位鍵並接入電源,此時你會看到電源LED燈變成橙色等閃爍,接著會變為白色燈閃爍,此時可以放開復位鍵,路由器這時已經是進入了刷機模式
- 此時電腦通過網線連線路由器,並將IP設定為手動並修改為
192.168.1.20
,掩碼改為255.255.255.0
,閘道器改為192.168.1.1
- 最後進入放置剛剛下載好的img的目錄
刷入openwrt:
通過 tftp
進行刷入,如果你是Mac OS,可以通過 brew install tftp
安裝 tftp
,如果是windows可以自行在網路上下載 tftp
工具。然後如圖進行刷入:
通常幾秒鐘便完成刷機,此時路由器會自動重啟並且進入openwrt。
此時記得將網路改回DHCP,便可以通過瀏覽器訪問 192.168.1.1
進入Openwrt的luci頁面了。
此時通過 System->Administration
進入管理員密碼設定,設定好密碼以及SSH後便完成了第一步。
II. 修改LAN IP
由於我這邊的光貓也是路由,並且分配的是 192.168.1.x
網段,為了避免衝突,在將其接入R7800 WAN口之前,我這邊將LAN IP修改為 99.1
,先SSH進入,然後輸入:
uci set network.lan.ipaddr=192.168.99.1 uci commit service network restart
修改好後,就可以將光貓出來的網線接入到WAN口,接入網際網路了。配置Wifi之類的比較簡單這裡就不說了。
III. 新增HOST
這裡我們可以修改host隨意用一個不常用但是好記的域名訪問,如果你覺得不需要可以跳過這步:
SSH進入路由器,然後修改 /etc/hosts
檔案,新增:
192.168.99.1 r.cc
儲存然後重啟 network
服務:
service network restart
IV. 上V2Ray
1. V2Ray在VPS端搭建與配置
要通過V2Ray進行翻牆,首先我們需要先有一臺已經配置好V2Ray的牆外的VPS,對於VPS的選擇與搭建可以參看這篇文章,下面我們就假定你已經通過該篇文章配置好了VPS,配置好後,你是一個Ubuntu,ok, 我們先開始搭建VPS端:
由於針對Ubuntu, 官方文件 中已經有提供指令碼安裝,我們就直接通過該指令碼進行安裝即可:
bash <(curl -L -s https://install.direct/go.sh)
安裝好後,我們對其進行配置,下面的配置 /etc/v2ray/config.json
檔案,該檔案如果不存在直接建立即可,如果存在將其內容完全替換為下面的內容,這裡我們假設你使用的埠是 29001
,以及用於識別的UUID: xxx-xxx-xxx-xx-xxx
(你可以通過 這裡 線上生成自己的UUID並替換):
{ "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", "loglevel": "warning" }, "inbound": { "port": 29001, "protocol": "vmess", "settings": { "clients": [ { "id": "xxx-xxx-xxx-xx-xxx", "level": 1, "alterId": 64 } ], "detour": { "to": "dynamicPort" } }, "streamSettings": { "network": "kcp" } }, "inboundDetour": [ { "protocol": "vmess", "port": "10000-20000", "tag": "dynamicPort", "settings": { "default": { "level": 1, "alterId": 32 } }, "allocate": { "strategy": "random", "concurrency": 2, "refresh": 3 }, "streamSettings": { "network": "kcp" } } ], "outbound": { "protocol": "freedom", "settings": {} }, "outboundDetour": [ { "protocol": "blackhole", "settings": {}, "tag": "blocked" } ], "transport": { "tcpSettings": { "connectionReuse": true }, "kcpSettings": { "mtu": 1350, "tti": 20, "uplinkCapacity": 100, "downlinkCapacity": 100, "congestion": false, "readBufferSize": 5, "writeBufferSize": 5, "header": { "type": "utp" } } } }
配置好後,可以通過 /usr/bin/v2ray/v2ray -test -config /etc/v2ray/config.json
來檢測下配置檔案的格式是否存在問題。
我們假設你使用的是 29001
埠,並且已經通過這篇文章設定好了通過 ufw
管理防火牆,因此這邊需要允許該埠的訪問:
ufw allow 29001
此時重啟 v2ray
服務便完成服務端配置:
service v2ray restart
2. V2Ray在路由器安裝配置
下面假設你已經根據教程將LAN IP修改為了 192.168.99.1
,並且已經設定好了SSH,以及你的電腦已經有了SCP的工具。
首先由於R7800是高通ARM架構的CPU,這邊我們先在 這裡的Release列表 下載arm架構的V2Ray,比如寫這篇文章的時候最新版本是v4.5.0,這裡我們就直接下載 這個v2ray-linux-arm.zip版本
如果需要驗證,下載好後可以通過對比 dgst 中描述的各類資訊進行比對。
然後解壓縮到 v2ray-linux-arm
資料夾,緊接著我們通過 SCP
將其傳到路由器的 /root/v2ray
的目錄下:
scp -r v2ray-linux-arm [email protected]:/root/v2ray
然後ssh進入路由器,然後按照常規的目錄結構咱們來放置以及配置好 V2Ray
:
cd /root/v2ray chmod +x v2ray v2ctl mkdir /usr/bin/v2ray mv v2ray v2ctl geoip.dat geosite.dat /usr/bin/v2ray/
除此之外 /root/v2ray
下面的其他檔案其實我們都沒有用到,可以直接刪除。緊接著我們建立 /etc/v2ray/config.json
檔案,並且將以下內容填入,這裡我們假設你的VPS的IP是 x.x.x.x
,以及你的埠是 29001
、以及剛剛在VPS上你填寫的UUID是 xxx-xxx-xxx-xx-xxx
:
{ "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", "loglevel": "warning" }, "outbound": { "protocol": "vmess", "settings": { "vnext": [ { "address": "x.x.x.x", "port": 29001, "users": [ { "id": "xxx-xxx-xxx-xx-xxx", "level": 1, "alterId": 64 } ] } ] }, "streamSettings": { "network": "kcp" }, "mux": { "enabled": true } }, "outboundDetour": [ { "protocol": "freedom", "settings": {}, "tag": "direct" } ], "inbound": { "protocol": "dokodemo-door", "port": 5353, "settings": { "address": "119.29.29.29", "port": 53, "network": "udp", "timeout": 0, "followRedirect": false } }, "inboundDetour": [ { "domainOverride": [ "http", "tls" ], "protocol": "dokodemo-door", "port": 1060, "settings": { "network": "tcp", "timeout": 30, "followRedirect": true } }, { "protocol": "socks", "port": 8080, "settings": { "auth": "noauth", "udp": false, "ip": "127.0.0.1" } } ], "routing": { "strategy": "rules", "settings": { "domainStrategy": "IPIfNonMatch", "rules": [ { "type": "field", "port": "1-52", "outboundTag": "direct" }, { "type": "field", "port": "54-79", "outboundTag": "direct" }, { "type": "field", "port": "81-442", "outboundTag": "direct" }, { "type": "field", "port": "444-3999", "outboundTag": "direct" }, { "type": "field", "port": "4001-65535", "outboundTag": "direct" }, { "domain": [ "vultr.com" ], "type": "field", "outboundTag": "direct" }, { "type": "chinasites", "outboundTag": "direct" }, { "type": "field", "ip": [ "0.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24", "192.0.2.0/24", "192.168.0.0/16", "198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "::1/128", "fc00::/7", "fe80::/10" ], "outboundTag": "direct" }, { "type": "chinaip", "outboundTag": "direct" } ] } }, "transport": { "tcpSettings": { "connectionReuse": true }, "kcpSettings": { "mtu": 1350, "tti": 20, "uplinkCapacity": 100, "downlinkCapacity": 100, "congestion": false, "readBufferSize": 5, "writeBufferSize": 5, "header": { "type": "utp" } } } }
配置好後依然可以通過 /usr/bin/v2ray/v2ray -test -config /etc/v2ray/config.json
這個來檢查配置檔案是否有效,注意將其中的VPS IP修改為你的VPS IP,UUID、埠改為你之前在VPS配置好的。
緊接著我們需要生效 v2ray
服務:
新增檔案 /etc/init.d/v2ray
,並填寫入以下內容:
#!/bin/sh /etc/rc.common # # Copyright (C) 2017 Ian Li <[email protected]> # # This is free software, licensed under the GNU General Public License v3. # See /LICENSE for more information. # START=90 USE_PROCD=1 start_service() { mkdir /var/log/v2ray > /dev/null 2>&1 procd_open_instance procd_set_param respawn procd_set_param command /usr/bin/v2ray/v2ray -config /etc/v2ray/config.json procd_set_param file /etc/v2ray/config.json procd_set_param stdout 1 procd_set_param stderr 1 procd_set_param pidfile /var/run/v2ray.pid procd_close_instance }
填寫好後設置其可執行的許可權:
chmod +x /etc/init.d/v2ray
然後我們為其啟用開機啟動:
/etc/init.d/v2ray enable
自此你可以通過以下指令先將v2ray服務啟動了:
service v2ray start
啟動後你就可以通過 ps | grep v2ray
看到該服務在運行了:
到這裡你依然不能翻牆,除非你的電腦代理到路由器的對應 1060
的埠上,我們不廢話,其實我們剛剛在路由器的 config.json
上已經配置了透明代理,只不過路由器的防火牆還沒有做轉發,現在我們開始配置這個轉發,來完成透明代理:
配置 /etc/firewall.user
檔案,在其中追加以下內容,需要特別注意將 x.x.x.x
改為你的VPS的IP:
iptables -t nat -N V2RAY iptables -t nat -A V2RAY -d x.x.x.x -j RETURN iptables -t nat -A V2RAY -d 0.0.0.0/8 -j RETURN iptables -t nat -A V2RAY -d 10.0.0.0/8 -j RETURN iptables -t nat -A V2RAY -d 127.0.0.0/8 -j RETURN iptables -t nat -A V2RAY -d 169.254.0.0/16 -j RETURN iptables -t nat -A V2RAY -d 172.16.0.0/12 -j RETURN iptables -t nat -A V2RAY -d 192.168.0.0/16 -j RETURN iptables -t nat -A V2RAY -d 224.0.0.0/4 -j RETURN iptables -t nat -A V2RAY -d 240.0.0.0/4 -j RETURN iptables -t nat -A V2RAY -p tcp -j REDIRECT --to-ports 1060 iptables -t nat -A PREROUTING -p tcp -j V2RAY
配置好儲存後,這邊我們重啟防火牆服務:
service firewall restart
重啟完成後你已經可以通過V2Ray翻牆了。
V. DNS汙染問題處理
最後我們可以稍微優化下DNS解析,防止DNS汙染的問題:
先安裝 dnsmasq
,預設情況下是已經安裝了的:
opkg install dnsmasq
然後通過 這裡 下載 dnsmasq.d.zip
檔案,然後進行解壓縮,解壓縮後,將該 dnsmasq.d
資料夾放入 /etc/
中,完成後,對 /etc/dnsmasq.conf
進行配置(這裡我們假設你的閘道器地址是 192.168.99.1
):
listen-address=127.0.0.1 listen-address=192.168.99.1 cache-size=102400 conf-dir=/etc/dnsmasq.d
最後通過重啟 dnsmasq
讓其生效
service dnsmasq restart
自此已經完全全部配置,Have Fun!