# GL.iNet 路由器設定彙整
> 涵蓋型號: GL-XE3000、GL-BE9300、GL-E5800
> 主題範圍: 防火牆 / TTL / 持久化 / SSH / Shadowsocks / SNAT / OpenVPN / Claude Code 部署
> 最後更新: 2026-06-01
> 提醒: 本文件包含網路設定、防火牆規則及代理服務設定,部分操作具地區法規敏感性,請自行評估使用情境
---
## 目錄
- [機型速查矩陣](#機型速查矩陣)
1. [TTL 修改與持久化(熱點限速繞過)](#1-ttl-修改與持久化熱點限速繞過)
2. [SSH 金鑰設定](#2-ssh-金鑰設定)
3. [SNAT 多 IP 出口](#3-snat-多-ip-出口)
4. [Shadowsocks 伺服器部署](#4-shadowsocks-伺服器部署)
5. [OpenVPN 自身流量路由](#5-openvpn-自身流量路由)
6. [系統管理常用指令](#6-系統管理常用指令)
7. [GL-XE3000:防火牆白名單](#7-gl-xe3000防火牆白名單)
8. [GL-BE9300:Claude Code 部署與持久化](#8-gl-be9300claude-code-部署與持久化)
9. [GL-MT6000:升級加固與 WAN SSH 安全](#9-gl-mt6000升級加固與-wan-ssh-安全)
10. [學習資源連結](#10-學習資源連結)
11. [安全提醒](#11-安全提醒)
---
## 機型速查矩陣
| 機型 | 韌體 / 防火牆 | 預設管理 IP | 主要相關章節 |
|------|--------------|------------|--------------|
| GL-XE3000 | OpenWrt 21.02 / fw3 | 192.168.8.1 | 7 防火牆白名單、1 TTL(fw3)、4 Shadowsocks |
| GL-E5800 | OpenWrt 23.05.4 / fw4 | 192.168.98.1 | 1 TTL(fw4) |
| GL-BE9300 | OpenWrt 23.05 / fw4 | — | 1 TTL(fw4)、8 Claude Code |
| GL-MT6000 | OpenWrt 21.02 / fw3 | — | 4 Shadowsocks(4.5)、9 升級加固與安全 |
| 全機型通用 | — | — | 2 SSH、3 SNAT、5 OpenVPN、6 系統管理指令 |
> fw3(21.02)持久化用 `/etc/firewall.user`;fw4(23.05)需 `config include` 並設 `option fw4_compatible '1'`。詳見第 1 章。
---
## 1. TTL 修改與持久化(熱點限速繞過)
### 1.1 指令對照表
| 平台 | 操作 | 指令 |
|------|------|------|
| OpenWRT | 設定 TTL=65 | `/usr/sbin/iptables -t mangle -I POSTROUTING 1 -j TTL --ttl-set 65` |
| OpenWRT | 查看規則 | `sudo iptables -t mangle -L POSTROUTING -n -v --line-numbers` |
| macOS | 查詢 TTL | `sysctl net.inet.ip.ttl` |
| macOS | 設定 TTL=65 | `sysctl -w net.inet.ip.ttl=65` |
### 1.2 OpenWRT 路由器設定
```sh
# 設定 TTL 為 65
/usr/sbin/iptables -t mangle -I POSTROUTING 1 -j TTL --ttl-set 65
# 驗證規則
sudo iptables -t mangle -L POSTROUTING -n -v --line-numbers
```
### 1.3 macOS 個別設定 TTL
```sh
# 查詢目前的 TTL
sysctl net.inet.ip.ttl
# 變更 TTL 為指定值(例如 65)
sysctl -w net.inet.ip.ttl=65
```
### 1.4 設定前後對比截圖
**Before**:

**After**:

### 1.5 效果驗證
| 狀態 | 截圖 |
|------|------|
| iptables 規則 |  |
| 規則列表 |  |
| 測試結果 |  |
### 1.6 持久化設定(重開機 / 防火牆 reload 後不失效)
> 1.2 的單行 `iptables -I POSTROUTING` 只是當下生效;OpenWrt 防火牆 reload 會清空整個 ruleset,重開機也會消失。要持久化必須掛進防火牆 include,且腳本要冪等(先刪後加)。**fw3 與 fw4 機制完全不同,務必先分清機型**。
| 機型 | 韌體 | 防火牆 | 持久化機制 | 關鍵雷點 |
|------|------|--------|-----------|----------|
| GL-XE3000 | OpenWrt 21.02 | fw3 | 內建 `/etc/firewall.user` | 預設那條 include 沒有 `option reload '1'`,只在 restart 跑、reload 不跑 → 要補上 |
| GL-E5800 / GL-BE9300 | OpenWrt 23.05 | fw4 (nftables) | 自訂 `config include` + 腳本 | fw4 **不吃 `option reload`**,script include 必須 `option fw4_compatible '1'` 才會被執行 |
#### A. fw3 機型(GL-XE3000)
fw3 內建 `/etc/firewall.user` 會在防火牆啟動時執行,但預設 include 沒帶 `reload '1'`,reload 時不會跑。先補旗標:
```sh
# 找出 /etc/firewall.user 的 include 索引並補 reload='1'
idx=$(uci show firewall | grep -E "include\[[0-9]+\].path=.?/etc/firewall.user" | sed -E 's/.*include\[([0-9]+)\].*/\1/')
uci set firewall.@include[$idx].reload='1'
uci commit firewall
```
再把冪等規則寫進 `/etc/firewall.user`:
```sh
cat >> /etc/firewall.user <<'EOF'
# >>> TTL65 BEGIN
# 先刪光所有重複再插一條 -> 冪等
while iptables -t mangle -D POSTROUTING -j TTL --ttl-set 65 2>/dev/null; do :; done
iptables -t mangle -I POSTROUTING 1 -j TTL --ttl-set 65
# <<< TTL65 END
EOF
/etc/init.d/firewall restart
```
注意事項:
- GL.iNet 原生有 `ETHERNET_TTL` / `TETHERING_TTL` chain(綁 `network.<wan>.ttl`),與上面的全域規則並存、不衝突,毋須刪除。
- 若曾用 daily cron 做持久化(如 `0 8 * * * iptables -t mangle -I POSTROUTING 1 -j TTL --ttl-set 65`),**務必移除**——它無條件 `-I` 不先刪,每天累積一條重複規則,且開機不會跑(重開機到隔天 08:00 之間全域規則是缺的):
```sh
sed -i '\#iptables -t mangle -I POSTROUTING 1 -j TTL --ttl-set 65#d' /etc/crontabs/root
/etc/init.d/cron restart
```
#### B. fw4 機型(GL-E5800 / GL-BE9300)
```sh
# 1. 冪等腳本
cat > /etc/firewall.user <<'EOF'
#!/bin/sh
iptables -t mangle -D POSTROUTING -j TTL --ttl-set 65 2>/dev/null
iptables -t mangle -I POSTROUTING 1 -j TTL --ttl-set 65
EOF
chmod +x /etc/firewall.user
# 2. 註冊 fw4 include(關鍵:fw4_compatible='1')
uci set firewall.ttl65=include
uci set firewall.ttl65.type='script'
uci set firewall.ttl65.path='/etc/firewall.user'
uci set firewall.ttl65.enabled='1'
uci set firewall.ttl65.fw4_compatible='1'
uci commit firewall
/etc/init.d/firewall reload
```
若 include 缺 `fw4_compatible '1'`,reload 時會出現警告並被略過:
```
[!] Section ttl65 option 'reload' is not supported by fw4
[!] Section ttl65 is not marked as compatible with fw4, ignoring section
[!] Section ttl65 requires 'option fw4_compatible 1' to be considered compatible
```
(GL.iNet 內建那些 `reload='1'` 的 include 同樣被 fw4 忽略,是走自家機制,別照抄 `reload='1'`。)
#### C. 驗證(兩種機型通用)
```sh
# 全域 TTL 規則應恆為 1(連續 reload 不增加 = 冪等成功)
iptables -t mangle -S POSTROUTING | grep -c -- '-j TTL --ttl-set 65'
iptables -t mangle -L POSTROUTING -n -v --line-numbers
```
> 提醒:以上設定隨 `/etc/config/` 與 `/etc/firewall.user` 保留,**重開機有效**;但韌體升級或回復原廠會清掉,需依本節重做(fw4 機型可考慮一併寫進 `sysupgrade.conf`,參見第 8、9 章作法)。
---
## 2. SSH 金鑰設定
### 2.1 產生 RSA 金鑰對
```sh
ssh-keygen -t rsa -f id_rsa -b 2048
```
參數說明:
- `-t rsa`: 金鑰類型為 RSA
- `-f id_rsa`: 檔案名稱
- `-b 2048`: 金鑰長度 2048 位元
> 註: 原文寫 `-s 2048` 應為 `-b`(bits),`-s` 是 signature provider 用途。
### 2.2 增加 Keypair 連線


---
## 3. SNAT 多 IP 出口
讓 LAN 段(`192.168.189.0/24`)對外連線時,從固定 IP 範圍輪流出口,常見用途為避免單一 IP 被限速或 ban。
```sh
iptables -t nat -I POSTROUTING 1 \
-s 192.168.189.0/24 -o eth0 \
-j SNAT --to-source 59.124.28.235-59.124.28.240
```
說明:
- `-s 192.168.189.0/24`: 來源 LAN 段
- `-o eth0`: 出口介面(依實際機型調整,部分 GL.iNet 機型可能是 `wan` 或 `br-wan`)
- `--to-source 59.124.28.235-59.124.28.240`: 6 個 IP 範圍,iptables 會以 hash 方式分配
要永久化,建議用 `/etc/firewall.user` 或 nftables 等同規則。
---
## 4. Shadowsocks 伺服器部署
### 4.1 安裝方式對照表
| 安裝類型 | 適用場景 | 套件名稱 |
|---------|---------|---------|
| Docker | 完整伺服器部署 | `dockerd docker docker-compose luci-app-dockerman` |
| Standalone | 獨立完整功能 | `shadowsocks-libev-ss-local/redir/rules/tunnel` + `luci-app-shadowsocks-libev` |
| 跳板模式 | 僅轉發功能 | `shadowsocks-libev-ss-redir` + `luci-app-shadowsocks-libev` |
### 4.2 Docker 方式安裝(GL-XE3000)
**安裝 Docker**:
```sh
opkg update
opkg install dockerd docker docker-compose luci-app-dockerman
/etc/init.d/dockerd enable
/etc/init.d/dockerd start
```
**docker-compose.yml**:
```yaml
version: '3.8'
services:
ssserver:
image: ghcr.io/shadowsocks/ssserver-rust:latest
container_name: ssserver
restart: unless-stopped
network_mode: host
command: >
ssserver
-s 0.0.0.0:9000
-m chacha20-ietf-poly1305
-k zhimakaimen
--udp-timeout 300
--no-delay
-v
environment:
- RUST_LOG=warn
- TZ=Asia/Taipei
```
**設定參數說明**:
| 參數 | 值 | 說明 |
|------|-----|------|
| 監聽位址 | `0.0.0.0:9000` | 所有介面,端口 9000 |
| 加密方式 | `chacha20-ietf-poly1305` | AEAD 加密 |
| 密碼 | `zhimakaimen` | 連線密碼(生產環境請更換) |
| UDP 逾時 | `300` 秒 | UDP 連線逾時時間 |
| 時區 | `Asia/Taipei` | 台北時區 |
**防火牆規則(允許 SS 連線)**:
```sh
uci add firewall rule
uci set firewall.@rule[-1].name='Allow-SS'
uci set firewall.@rule[-1].src='wan'
uci set firewall.@rule[-1].proto='tcp udp'
uci set firewall.@rule[-1].dest_port='9000'
uci set firewall.@rule[-1].target='ACCEPT'
uci commit firewall
/etc/init.d/firewall restart
```
### 4.3 Standalone 方式安裝(含 UI)
```sh
opkg update
opkg install shadowsocks-libev-ss-local \
shadowsocks-libev-ss-redir \
shadowsocks-libev-ss-rules \
shadowsocks-libev-ss-tunnel \
luci-app-shadowsocks-libev
```
### 4.4 跳板模式
**方式 A(含 UI)**:
```sh
opkg update
opkg install shadowsocks-libev-ss-redir luci-app-shadowsocks-libev
```
**方式 B(僅核心)**:
```sh
opkg update
opkg install shadowsocks-libev-ss-redir
```
### 4.5 MT6000 型號特殊安裝(Docker 強制覆蓋依賴)
```sh
opkg update
opkg install dockerd --force-depends --force-overwrite
/etc/init.d/dockerd enable
/etc/init.d/dockerd start
```
---
## 5. OpenVPN 自身流量路由
**場景**: 透過 Router 撥 OpenVPN,LAN 內裝置都能走 VPN,但 Router 自己(router-self traffic)走預設出口,無法連到 VPN 內網 IP。
**解法**: 用 policy routing 把指定目的 IP 從 Router 自己也導入 VPN 的 routing table。
### 5.1 找出 OpenVPN routing table 編號
```sh
ip route show table all | grep 'default.*dev ovpnclient'
# 輸出範例:
# default dev ovpnclient1 table 1011 scope link
# ^^^^
# 這就是答案
```
腳本自動抓:
```sh
ip route show table all | awk '/^default.*dev ovpnclient/ {
for (i=1; i<=NF; i++) if ($i=="table") print $(i+1); exit
}'
```
### 5.2 永久化腳本
```sh
cat > /etc/vpn-dst-route.sh <<'EOF'
#!/bin/sh
# 把指定目的 IP 的「路由器本機」流量導入 OpenVPN client 的 routing table
PRI=11000
DSTS="10.244.64.16/32" # 多個 IP/網段用空白隔開
# 自動偵測 VPN routing table
TBL=$(ip route show table all | awk '/^default.*dev ovpnclient/ {for(i=1;i<=NF;i++) if($i=="table") print $(i+1); exit}')
[ -z "$TBL" ] && { echo "找不到 OpenVPN client 的 routing table,VPN 是否啟動?" >&2; exit 1; }
for D in $DSTS; do
ip rule del to "$D" lookup $TBL priority $PRI 2>/dev/null
ip rule add to "$D" lookup $TBL priority $PRI
done
EOF
chmod +x /etc/vpn-dst-route.sh
/etc/vpn-dst-route.sh
# 開機自動執行
grep -qF '/etc/vpn-dst-route.sh' /etc/rc.local \
|| sed -i '/^exit 0/i /etc/vpn-dst-route.sh' /etc/rc.local
```
---
## 6. 系統管理常用指令
### 6.1 關機指令(GL.iNet)
透過 ubus 呼叫 MCU 關機:
```sh
ubus call mcu cmd_json '{"power_off":"1"}'
```
### 6.2 Netcat 安裝
```sh
opkg update
opkg install netcat
```
### 6.3 防火牆速查
```sh
# 查看所有防火牆規則
uci show firewall
# 查看轉發規則
uci show firewall | grep redirect
# 查看白名單(fw3 機型用 ipset;fw4 機型改用 nft list set inet fw4 <name>)
ipset list whitelist
# 重啟防火牆
/etc/init.d/firewall restart
```
### 6.4 Docker 速查
```sh
docker ps -a # 容器狀態
docker logs ssserver # 容器日誌
docker restart ssserver # 重啟
docker stop ssserver # 停止
```
### 6.5 OpenWRT 套件管理
```sh
opkg update # 更新套件列表
opkg find shadowsocks* # 搜尋
opkg list-installed | grep shadowsocks # 已安裝
opkg remove shadowsocks-libev-ss-redir # 移除
```
---
## 7. GL-XE3000:防火牆白名單
> 後端說明:GL-XE3000 為 OpenWrt 21.02 / **fw3**,防火牆 ipset 由 `ipset` 命令管理(**此韌體無 `nft`**)。runtime 查詢與增刪一律用 `ipset`,不可用 `nft`。fw4 機型(23.05,如 GL-E5800 / GL-BE9300)才改用 `nft list set inet fw4 <name>`。永久化設定(7.2、7.3 的 `uci ... ipset`)fw3 / fw4 通用。
### 7.1 指令總表
| 操作 | 指令(fw3 / ipset) | 生效範圍 |
|------|------|----------|
| 查詢轉發規則 | `uci show firewall \| grep redirect` | 一次性 |
| 查詢白名單 | `ipset list whitelist` | 一次性 |
| 暫時新增 IP | `ipset add whitelist 49.216.185.183` | 重啟後失效 |
| 暫時移除 IP | `ipset del whitelist 49.216.185.183` | 重啟後失效 |
### 7.2 建立永久白名單
```sh
# 建立白名單 ipset
uci add firewall ipset
uci set firewall.@ipset[-1].name='whitelist'
uci set firewall.@ipset[-1].family='ipv4'
uci set firewall.@ipset[-1].storage='hash'
uci set firewall.@ipset[-1].match='src_ip'
uci set firewall.@ipset[-1].entry='114.36.10.68 49.216.185.183'
# 套用到轉發規則
uci delete firewall.@redirect[0].src_ip
uci set firewall.@redirect[0].ipset='whitelist'
# 提交設定並重啟防火牆
uci commit firewall
/etc/init.d/firewall restart
```
預設白名單 IP:
- `114.36.10.68`
- `49.216.185.183`
### 7.3 永久新增 / 移除 IP
**永久新增**:
```sh
uci add_list firewall.@ipset[0].entry='49.216.185.183'
uci commit firewall
/etc/init.d/firewall restart
```
**永久移除**(精準刪除指定值):
```sh
uci del_list firewall.@ipset[0].entry='49.216.185.183'
uci commit firewall
/etc/init.d/firewall restart
```
---
## 8. GL-BE9300:Claude Code 部署與持久化
> 環境: GL.iNet GL-BE9300(OpenWrt 23.05-SNAPSHOT, aarch64 / musl libc, Node 18.20.1)
> 安裝版本: Claude Code 2.1.143
### 8.1 問題現象
執行 `/usr/bin/claude` 報錯:
```
Error: claude native binary not installed.
Either postinstall did not run (--ignore-scripts, some pnpm configs)
or the platform-native optional dependency was not downloaded
(--omit=optional).
```
### 8.2 根本原因
Claude Code 採「wrapper + 平台專屬 native binary」設計:
- 主套件 `@anthropic-ai/claude-code` 只含 wrapper 與 `install.cjs`
- 真正 binary 在 8 個 `optionalDependencies` 之一(依平台選用)
- `postinstall` 階段由 `install.cjs` 偵測平台、從對應 optional 套件複製 binary 到 `bin/claude.exe`
GL-BE9300 需要 `@anthropic-ai/claude-code-linux-arm64-musl`(OpenWrt 使用 musl libc)。
**故障狀態**:
| 項目 | 預期 | 實際 |
|------|------|------|
| `linux-arm64-musl` 套件目錄 | 含 `claude` binary(~226 MB) | 空目錄 |
| `bin/claude.exe` | 真實 ELF executable | placeholder |
| `/usr/bin/claude` symlink | 指向可執行檔 | 指向 placeholder |
npm 初次安裝時 optional dependency 內容未下載(可能 `--omit=optional`、`--ignore-scripts` 或網路中斷)。
### 8.3 修復步驟
**Step 1: 嘗試重裝(失敗)**
```sh
npm install -g @anthropic-ai/claude-code --include=optional
# npm ERR! ENOTEMPTY: directory not empty,
# rename '.../claude-code' -> '.../.claude-code-XXXX'
```
npm atomic rename 機制被殘留 staging 目錄卡住。
**Step 2: 清除殘留後重裝(成功)**
```sh
cd /usr/lib/node_modules/@anthropic-ai
rm -rf claude-code .claude-code-* claude-code-linux-arm64-musl
npm install -g @anthropic-ai/claude-code --include=optional
```
**驗證結果**:
```sh
$ file /usr/lib/node_modules/@anthropic-ai/claude-code/bin/claude.exe
ELF 64-bit LSB executable, ARM aarch64, dynamically linked,
interpreter /lib/ld-musl-aarch64.so.1
$ claude --version
2.1.143 (Claude Code)
```
### 8.4 持久化分析
**檔案系統結構**:
```
/ overlayfs (lowerdir=/, upperdir=/overlay/upper)
/overlay /dev/loop0 ext4 (持久化儲存,6.7 GB)
/tmp tmpfs (揮發)
```
寫入 `/usr/lib/node_modules/...` 會落到 `/overlay/upper/usr/lib/node_modules/...`,重開機後保留。
**排程與重置機制盤點**:
| 機制 | 觸發時機 | 是否清 overlay | 此機型啟用 |
|------|----------|----------------|-------------|
| 每週一到五 09:00 reboot | `/etc/crontabs/root` | **否** | 啟用 |
| `auto_timezone` / `modem_sim_status_check` / `gl-update-cable-mac` | cron 每分鐘/30 分鐘 | 否 | 啟用 |
| sysupgrade(韌體升級) | 手動 / GL.iNet UI | **是**(只保留 `sysupgrade.conf` 列出的路徑) | 視操作 |
| A/B partition trymode | 升級失敗自動切回 | 切到另一個 overlay | **不適用**(無雙韌體分割) |
| 自動 firmware update | `glconfig` | 是 | **未啟用** |
| `jffs2reset` / `firstboot` / 實體 reset 按鈕 | 手動 | 是 | 視操作 |
| watchdog 異常重啟 | 系統 | 否 | 無異常記錄 |
**結論**:
- 每日自動 reboot 不會清掉安裝(驗證: uptime 跨過一次週五 09:00 自動重啟後 claude 仍正常)
- 真正會破壞安裝的情境: 手動韌體升級、實體 reset 按鈕、`firstboot` 指令
- 一開始以為「裝完又壞掉」其實是首次安裝就壞了(optional dep 沒下載),不是被排程清掉
### 8.5 持久化加固(sysupgrade.conf)
預設 `/etc/sysupgrade.conf` 只保留 `/etc/config/gl_nas/`,韌體升級會清掉 claude-code。加入保留條目:
```sh
cat >> /etc/sysupgrade.conf <<'EOF'
# Claude Code persistence across sysupgrade
/usr/lib/node_modules/@anthropic-ai/
/usr/bin/claude
EOF
```
驗證:
```sh
sysupgrade -l | grep -E "claude|anthropic"
```
預期輸出(關鍵檔案均在):
```
/usr/bin/claude
/usr/lib/node_modules/@anthropic-ai/claude-code/bin/claude.exe
/usr/lib/node_modules/@anthropic-ai/claude-code/install.cjs
/usr/lib/node_modules/@anthropic-ai/claude-code/cli-wrapper.cjs
/usr/lib/node_modules/@anthropic-ai/claude-code/node_modules/@anthropic-ai/claude-code-linux-arm64-musl/claude
...
```
備份檔: `/etc/sysupgrade.conf.bak`(誤動可還原)
### 8.6 後續維護
**升級後相容性風險**:
韌體升級會替換 base system,可能變動:
- musl libc 版本 → 影響 dynamic linking
- Node 版本 → 影響 wrapper 執行(`engines.node >= 18`)
- 系統路徑或 npm 全域目錄
建議流程: 升級後先測 `claude --version`;若報錯,直接重跑:
```sh
npm install -g @anthropic-ai/claude-code --include=optional
```
**升級 Claude Code 自己**:
```sh
npm install -g @anthropic-ai/claude-code@latest --include=optional
```
務必帶 `--include=optional`,否則會再次踩到 native binary 沒下載的雷。
**資源使用考量**:
- 路由器 RAM 僅 ~883 MB,跑大型 codebase 索引/分析會吃緊
- `/overlay` 剩餘 5.5 GB,claude-code 自己佔 ~230 MB
- 適用場景: SSH session 跳板、輕量任務、查詢;不建議跑長時間並行 agent 工作流
### 8.7 健康檢查速查
```sh
# 健康檢查
claude --version
file /usr/lib/node_modules/@anthropic-ai/claude-code/bin/claude.exe
# 重裝(含 optional)
rm -rf /usr/lib/node_modules/@anthropic-ai/{claude-code,.claude-code-*,claude-code-linux-arm64-musl}
npm install -g @anthropic-ai/claude-code --include=optional
# 確認 sysupgrade 保護生效
sysupgrade -l | grep -E "claude|anthropic"
# 確認當前平台符合預期
uname -m # 應為 aarch64
ldd --version 2>&1 # 應為 musl libc
node -p "process.platform + '-' + process.arch" # linux-arm64
```
---
## 9. GL-MT6000:升級加固與 WAN SSH 安全
GL-MT6000 跟 BE9300 不同:韌體 21.02 比較舊,但 GL.iNet 在 `/lib/upgrade/keep.d/` 預設已保留大量目錄(含 `/etc/config/` 整個、SSH key、openvpn、samba、tailscale、AdGuardHome 等)。需要額外加固的只有用戶自訂安裝。
### 9.1 預設保留檢視
```sh
# 看 sysupgrade 會保留哪些檔案(含 keep.d 內容)
sysupgrade -l
# 看 GL.iNet 內建保留清單來源
ls /lib/upgrade/keep.d/
```
### 9.2 自訂需要加固的條目
| 路徑 | 內容 | 是否保留 |
|------|------|----------|
| `/root/ssserver/docker-compose.yml` | Shadowsocks 容器設定 | 加固 |
| `/etc/docker/key.json` | Docker daemon 身分 | 加固 |
| `/opt/docker/` | Image cache + container 資料(94 MB) | **不保**(升級後重 pull / 重 up) |
| `/opt/containerd/` | containerd metadata | **不保** |
不保 `/opt/docker/` 的理由:跨 docker major 版本升級時 storage driver 可能不相容導致 daemon 起不來;保留 `compose.yml` 加上升級後重跑 `docker compose up -d` 反而更穩。
### 9.3 加固指令
```sh
cp /etc/sysupgrade.conf /etc/sysupgrade.conf.bak.$(date +%Y%m%d)
cat >> /etc/sysupgrade.conf <<'EOF'
# Custom: protect user installs not covered by /lib/upgrade/keep.d
/root/
/etc/docker/
EOF
# 驗證
sysupgrade -l | grep -E '^/root|^/etc/docker'
# 預期輸出:
# /etc/docker/key.json
# /root/ssserver/docker-compose.yml
```
### 9.4 升級後重建 SOP
```sh
# 1. 確認自訂設定還在
ls /root/ssserver/docker-compose.yml
ls /etc/docker/key.json
# 2. 啟動 Docker(新韌體須帶 dockerd 套件)
/etc/init.d/dockerd enable
/etc/init.d/dockerd start
# 3. 重建 ssserver 容器(會重 pull image)
cd /root/ssserver && docker compose up -d
# 4. 驗證
docker ps | grep ssserver
netstat -tlnp 2>/dev/null | grep 9000
```
### 9.5 安全提醒:WAN SSH 攻擊現況
MT6000 開啟了 WAN 22 port (`firewall.ssh_wan`),實測 dropbear log 顯示**持續被全網掃描攻擊**:
```
112.216.129.27 Bad password attempt for 'root'
189.147.27.156 匿名連線嘗試
221.156.137.102 多次掃描
74.82.47.3 Shodan / Censys 掃描器
2.57.121.x 匿名爬蟲
```
dropbear 預設只接受 pubkey(沒看到 password auth 成功),技術上沒被攻破,但建議擇一:
| 方案 | uci 指令 |
|------|---------|
| 完全關 WAN SSH | `uci delete firewall.ssh_wan; uci delete firewall.ssh_wan6; uci commit firewall; /etc/init.d/firewall restart` |
| 改 SSH port | `uci set dropbear.@dropbear[0].Port=22222; uci commit dropbear; /etc/init.d/dropbear restart` 並把 `firewall.ssh_wan.dest_port` 一併改 |
| 限制 source IP | `uci set firewall.ssh_wan.src_ip='114.36.10.68'; uci commit firewall; /etc/init.d/firewall restart` |
### 9.6 重複 Allow-SS 規則清理
uci 設定中曾有兩條完全一樣的 `Allow-SS` 規則(`@rule[26]` 和 `@rule[30]`),重複無害但易混淆。清除方法:
```sh
uci delete firewall.@rule[30]
uci commit firewall
/etc/init.d/firewall restart
```
清掉後 `firewall.@rule[26]` 保留作為唯一 Allow-SS 規則。
---
## 10. 學習資源連結
### 10.1 官方文件與教學
| 類別 | 標題 | 連結 |
|------|------|------|
| TTL 修改 | TTL modification for outgoing traffic with OpenWRT | [連結](https://www.maroonmed.com/ttl-modification-for-outgoing-traffic-with-openwrt/) |
| T-Mobile ISP | T-Mobile Home ISP Service Review with OpenWRT | [連結](https://bostonenginerd.com/posts/tmobile-isp/) |
| GL-X3000 | New GL-X3000 Spitz AX owner (T-Mobile Home Internet) | [Reddit](https://www.reddit.com/r/GlInet/comments/15ukqvv/new_glx3000_spitz_ax_owner_tmobile_home_internet/) |
| TTL 設定 | Change outgoing TTL | [GL.iNet Forum](https://forum.gl-inet.com/t/change-outgoing-ttl/2096) |
| Bridge 模式 | GL-X3000 Bridge Mode WAN IP Passthrough | [GL.iNet Forum](https://forum.gl-inet.com/t/gl-x3000-bridge-mode-wan-ip-passthrough/32715) |
### 10.2 macOS 相關
| 工具 / 主題 | 連結 |
|-------------|------|
| Pythonista 3 | [App Store](https://apps.apple.com/us/app/pythonista-3/id1085978097) |
| Automator Workflow (TTL 65) | [Reddit](https://www.reddit.com/r/Visible/comments/zvfc3l/macos_automator_workflow_to_enable_ttl_65/) |
### 10.3 中文資源
| 主題 | 連結 |
|------|------|
| TTL 修改 bypass hotspot quota | [美卡論壇](https://www.uscardforum.com/t/topic/233263/12?page=2) |
| 4G / 5G 熱點分享 TTL 修改法 | [WorkXPlay](https://uni.workxplay.net/t/4g-5g-ttl/183) |
---
## 11. 安全提醒
### 11.1 重要注意事項
1. **Shadowsocks 密碼**: 預設密碼 `zhimakaimen` 僅供測試,生產環境請更換強密碼
2. **防火牆規則**: 白名單 IP 應定期檢查,移除不再使用的 IP
3. **TTL 修改**: 部分電信商可能偵測 TTL 修改行為,請遵守使用條款
4. **SSH 金鑰**: 生成的私鑰請妥善保管,不要外洩
5. **Docker 安全**: 定期更新容器映像檔
6. **API token / 憑證**: 切勿貼入此文件;HackMD note 預設可公開讀取
### 11.2 最佳實踐
- 使用強密碼和金鑰認證
- 定期更新系統和套件
- 最小權限原則開放防火牆
- 監控系統日誌
- 備份重要設定(特別是 `/etc/config/`、`/etc/firewall.user`、自訂腳本)
---
**適用型號**: GL-XE3000、GL-BE9300、GL-E5800、GL-MT6000
**韌體版本**: OpenWRT 21.02+ / 23.05
**最後更新**: 2026-06-01