刷入 Asuswrt-Merlin 固件#
不必擔心把路由器刷廢了,華碩的路由器可以讓你一鍵重置回來
1)下載固件
先到 https://www.asuswrt-merlin.net/download 下載相應的固件,並解壓。(當前最新 RT-AC86U_386.13_2.zip
)
2)升級固件
登錄到你的路由器後台 http://192.168.50.1/
,在 系統管理 > 固件升級
中上傳固件文件(如 RT-AC86U_386.13_2_ubi.w
)
3)打開 JFFS 分區
系統管理 > 系統設置 > Persistent JFFS2 partition
Format JFFS partition at next boot
-否
Enable JFFS custom scripts and configs
-是
4)打開 SSH 登錄
系統管理 > 系統設置 > SSH Daemon
Allow SSH password login
-是
系統分區說明#
admin@RT-AC86U-67A0:/tmp/home/root# df -h
Filesystem Size Used Available Use% Mounted on
ubi:rootfs_ubifs 77.2M 67.1M 10.0M 87% /
devtmpfs 207.9M 0 207.9M 0% /dev
tmpfs 208.0M 300.0K 207.7M 0% /var
tmpfs 208.0M 16.2M 191.8M 8% /tmp/mnt
mtd:bootfs 4.4M 3.3M 1.1M 75% /bootfs
tmpfs 208.0M 16.2M 191.8M 8% /tmp/mnt
mtd:data 8.0M 592.0K 7.4M 7% /data
tmpfs 208.0M 16.2M 191.8M 8% /tmp
/dev/mtdblock9 47.0M 34.2M 12.8M 73% /jffs
/tmp
空間較大,設備重啟後會清空,可用來臨時下載文件。/jffs
空間較小,設備重啟後仍保留,可用來保存配置文件、安裝程序(有限)。
現在新版的 tailscale_1.68.2_arm64.tgz
會釋放 tailscale 15.4M
與 tailscaled 31.1M
兩個核心可執行文件。但 /jffs
空間有限,裝不下 tailscale
與 tailscaled
,可以利用 /tmp
分區持載可執行文件(參考 adyanth/openwrt-tailscale-enabler 在使用時才下載可執行文件)
為了得到穩定的使用體驗,我計劃只將 tailscaled
安裝在 /jffs/tailscale/tailscaled
,而 tailscale
不經常使用可以在使用時才下載到 /tmp/tailscale
。
安裝 Tailscale#
/jffs/tailscale/tailscale
#!/bin/sh
# https://github.com/adyanth/openwrt-tailscale-enabler/blob/main/usr/bin/tailscale
set -e
if [ ! -f /tmp/tailscaled ]; then
arch=`uname -m`
if [ "$arch" == "mips" ]; then
endianness=`echo -n I | hexdump -o | awk '{ print (substr($2,6,1)=="1") ? "le" : ""; exit }'`
elif [ "$arch" == "armv7l" ]; then
arch=arm
elif [ "$arch" == "aarch64" ]; then
arch=arm64
elif [ "$arch" == "x86_64" ]; then
arch=amd64
fi
tailscale_version="1.68.2"
latest_version=`wget -O- https://pkgs.tailscale.com/stable/ | grep tailscale_ | head -1 | cut -d'_' -f 2`
if [ "$tailscale_version" != "$latest_version" ]; then
tailscale_version=$latest_version
fi
version="${tailscale_version}_${arch}${endianness}"
echo "Downloading Tailscale ${version} .."
echo -e "tailscale_${version}/tailscaled" > /tmp/tailscale_${version}_files.txt
wget -O- https://pkgs.tailscale.com/stable/tailscale_${version}.tgz | tar x -zvf - -C /tmp -T /tmp/tailscale_${version}_files.txt
mv /tmp/tailscale_$version/* /tmp
rm -rf /tmp/tailscale_${version}*
echo "Done!"
fi
/tmp/tailscaled "$@"
/jffs/tailscale/tailscaled-startup.sh
#!/bin/sh
tailscaled_pid=`pidof tailscaled`
if [ -z "$tailscaled_pid" ]
then
modprobe tun
nohup /jffs/tailscale/tailscaled --no-logs-no-support --state=/jffs/tailscale/tailscaled.state --statedir=/jffs/tailscale >/dev/null 2>&1 &
else
echo "tailscaled (pid:$tailscaled_pid) is running..."
fi
if [ -x /opt/bin/tailscale ]; then tailscale down; tailscale up; fi
/bin/sh /jffs/tailscale/tailscale-nat-setup.sh
借助上面的腳本下載 /tmp/tailscale
與 /tmp/tailscaled
,再手動將 taiscaled
固化至 /jffs/tailscale/tailscaled
mkdir -p /jffs/tailscale
chmod +x /jffs/tailscale/tailscale /jffs/tailscale/tailscaled-startup.sh
/jffs/tailscale/tailscale # 下載
mv /tmp/tailscaled /jffs/tailscale/tailscaled
/jffs/tailscale/tailscaled-startup.sh # 啟動 tailscaled
/jffs/tailscale/tailscale up
# /jffs/tailscale/tailscale set ...
設置開機啟動#
Asuswrt-Merlin 為我們預留了多種事件的執行點,如:
wan-start
firewall-start
nat-start
init-start
- ...
可以利用這些事件的執行腳本進行拓展出各種玩法,如實現我們的 tailscale 開機啟動功能:
/jffs/scripts/nat-start
#!/bin/sh
modprobe tun
/bin/sh /jffs/tailscale/tailscale-nat-setup.sh
/jffs/scripts/firewall-start
#!/bin/sh
/bin/sh /jffs/tailscale/tailscaled-startup.sh
/jffs/tailscale/tailscale-nat-setup.sh
#!/bin/sh
# https://www.snbforums.com/threads/a-guide-about-installing-zerotier-on-asus-ac68u-router.42648/
logger -t "custom iptables" "Enter" -p user.notice
if ! iptables -C INPUT -i tailscale0 -j ACCEPT ; then
# tailscale nat
iptables -I INPUT -i tailscale0 -j ACCEPT
iptables -I FORWARD -i tailscale0 -j ACCEPT
iptables -I FORWARD -o tailscale0 -j ACCEPT
iptables -t nat -I POSTROUTING -o tailscale0 -j MASQUERADE
logger -t "custom iptables" "rules added" -p user.notice
else
logger -t "custom iptables" "rules existed skip" -p user.notice
fi
參考鏈接#
- https://gist.github.com/y0ngb1n/3d5c068ab191e6cc64254ad451047435
- https://github.com/haoel/haoel.github.io?tab=readme-ov-file#8-%E5%AE%B6%E7%94%A8%E9%80%8F%E6%98%8E%E7%BD%91%E5%85%B3
- https://github.com/adyanth/openwrt-tailscale-enabler
- https://pkgs.tailscale.com/stable/#static
- https://github.com/RMerl/asuswrt-merlin.ng/wiki/User-scripts
- https://github.com/RMerl/asuswrt-merlin.ng/wiki/Entware
- https://github.com/RMerl/asuswrt-merlin.ng/wiki/Installing-Tailscale-through-Entware
- https://www.snbforums.com/threads/a-guide-about-installing-zerotier-on-asus-ac68u-router.42648/