manjaro-os

记录manjaro的安装过程。

安装操作系统

https://manjaro.org/products/download/x86

GNOME is a modern desktop, the layout is different from other options but easy and intuitive to learn.

优化apt

Recommend: Add/Remove Software & Preferences->Use mirrors from: Change to China, and Refresh Mirrors.

Upgrade:

1
2
3
4
5
6
7
sudo pacman -Syu

#如果报错执行:
pacman-key --init
pacman-key --populate archlinuxarm
pacman -Sy archlinux-keyring
pacman -Syu

安装基础包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#pacman
#https://zhuanlan.zhihu.com/p/383694450
sudo pacman -S base-devel cmake pkgconf pacman-contrib vim xorg-mkfontscale net-tools jq lrzsz --noconfirm --needed

#yay
sudo pacman -S yay
#将 Yay 升级到新版本
yay -Sua
#升级所有包(含 AUR)
pacman -Syu
yay -Syu
#清理不需要的依赖
yay -Yc
sudo pacman -Sc
#清空整个缓存目录(/var/cache/pacman/pkg/)
#sudo pacman -Scc
#降级软件包版本
yay -S downgrade
sudo downgrade 包名
#自动化安装
yay -S packagename --noconfirm --needed

#paru
#https://zhuanlan.zhihu.com/p/350920414
git clone https://aur.archlinux.org/paru.git
cd paru
makepkg -si
#usage like yay

#debtap
yay -S debtap
debtap package
sudo pacman -U package.xtz

#homebrew
#https://brew.sh/
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


#安装输入法
#https://zhuanlan.zhihu.com/p/468426138
sudo pacman -Rs $(pacman -Qsq fcitx)
sudo pacman -S fcitx5 fcitx5-configtool fcitx5-qt fcitx5-gtk fcitx5-chinese-addons --noconfirm --needed

#安装Input Method Panel
https://extensions.gnome.org/extension/261/kimpanel/

#安装sogou
#yay -S fcitx5-sogou
#reboot

# Windows字体
https://rrroger.github.io/notebook/linux/Ubuntu%E5%AE%89%E8%A3%85%E5%BE%AE%E8%BD%AF%E5%AD%97%E4%BD%93.html
https://www.cnblogs.com/liutongqing/p/7923297.html

sudo git clone https://github.com/fernvenue/microsoft-yahei.git /usr/share/fonts/truetype/windows-font
sudo chmod -R 777 /usr/share/fonts/truetype/windows-font
cd /usr/share/fonts/truetype/windows-font
sudo rm -fr /usr/share/fonts/truetype/windows-font/.git
sudo mkfontscale
sudo mkfontdir
sudo fc-cache -fv
#查看已经安装的中文字体
fc-list :lang=zh

#常用软件
yay -S microsoft-edge-stable-bin
#旧机器需要在/usr/share/applications/microsoft-edge.desktop中添加:Exec=/usr/bin/microsoft-edge-stable --disable-gpu %U
#betterbird安装后,需要安装plugin: Minimize on Close
yay -S betterbird
yay -S wps-office-cn
#yay -Ss visual-studio-code
yay -S visual-studio-code-bin
yay -S cursor-bin
yay -S safeeyes
yay -S snipaste
#rsync -avP dave@192.168.3.37:~/.config/tabby ~/.config/
yay -S tabby-bin
yay -S feishu-bin
yay -S google-chrome
yay -S lx-music
yay -S musicfree
yay -S wechat-bin
yay -S xunlei-bin
yay -S alacarte
yay -S keepassxc
yay -S figma-linux-bin
yay -S pwgen
yay -S media-downloader
#多屏壁纸
yay -S hydrapaper
#录屏
yay -S kooha
sudo pacman -Syu ffmpeg vlc mpv celluloid
#Typora
#https://github.com/SSRVodka/typora-aur-1.9.3-1
wget https://github.com/SSRVodka/typora-aur-1.9.3-1/releases/download/1.9.3/typora_1.9.3_amd64.deb
debtap typora_1.9.3_amd64.deb
sudo pacman -U typora-1.9.3-1-x86_64.pkg.tar.zst

#ulauncher
#https://ulauncher.io/
cd /tmp && git clone https://aur.archlinux.org/ulauncher.git && cd ulauncher && makepkg -is


#Tweaks->Startup Applications
Betterbird
Ulauncher
Safe Eyes
Snipate
Feishu

#快捷键
Snipaste Snipaste snip -> F1
ulauncher ulauncher-toggle -> Alt+Space
xdg-open xdg-open . -> Super+E
显示桌面:搜索Hide all normal windows,设置Super+D

#kubectl:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv kubectl /usr/local/bin/

#.zshrc
alias ll="ls -l"
alias history='history 1'
alias yay="yay --noconfirm --needed"
alias pacman="pacman --noconfirm --needed"
alias paru="paru --noconfirm --needed"
alias sudo='sudo '
alias rm="/works/shell/rm.sh"
alias k=kubectl
#source <(kubectl completion bash | sed s/kubectl/k/g)

function proxy_off(){
unset http_proxy
unset https_proxy
echo -e "The proxy has been closed!"
}
function proxy_on() {
export no_proxy="127.0.0.1,localhost,10.0.0.0/8,172.0.0.0/8,192.168.0.0/16,*.zerofinance.net,*.aliyun.com,*.163.com,*.docker-cn.com,registry.gcalls.cn"
export http_proxy="http://127.0.0.1:1082"
export https_proxy=$http_proxy
echo -e "The proxy has been opened!"
}

. ~/.zshrc

#git
git config --global user.name "dave.zhao"
git config --global user.email dave.zhao@zerofinance.com
git config --global core.autocrlf false
git config --global core.safecrlf warn
git config --global core.filemode false
git config --global core.whitespace cr-at-eol
git config --global credential.helper store

Yay命令

https://wiki.archlinuxcn.org/wiki/Yay

https://ehewen.com/blog/yay/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
功能	                  命令
搜索包(官方 + AUR) yay 包名
安装软件包 yay -S 包名
升级所有包(含 AUR) yay -Syu
清理缓存文件 yay -Sc
删除无用依赖 yay -Yc
删除软件包及配置 yay -Rns 包名
仅安装 AUR 包 yay -S 包名 --aur
仅安装官方包 yay -S 包名 --repo
搜索安装包 yay -Ss 包名
查看包信息 yay -Si 包名
查看包的文件路径 yay -Ql 包名
查找某文件属于哪个包 yay -Qo 路径
查看包的详情 yay -Qi 包名
查看所有 AUR 安装包 yay -Qm
清理系统垃圾 yay -Sc && yay -Yc

howdy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#https://www.cnblogs.com/gardenialyx/p/19104354
#https://www.cnblogs.com/dingnosakura/p/18223572
yay -S howdy-git

#list camera
v4l2-ctl --list-devices

#修改 Howdy 配置文件
sudo vim /etc/howdy/config.ini
certainty = 4.5
device_path = /dev/video0


#如果你的摄像头有红外功能,还可以在最后一行加上这一句来让你的人脸识别在黑暗的环境下给你自动补光:
use_ir = true

#录入面部信息
#sudo howdy add -U dave
sudo howdy add

#删除人脸
#sudo howdy -U dave clear
sudo howdy clear

sudo vim /etc/pam.d/system-auth
#%PAM-1.0

auth sufficient pam_unix.so try_first_pass likeauth nullok
auth sufficient /usr/lib/security/pam_howdy.so

#测试人脸识别
sudo howdy test
#测试 sudo
sudo -i

扩展

1
2
3
4
#go to https://extensions.gnome.org/ and search:
Desktop Widgets(Desktop Clock)
Disable 3 Finger Gestures Redux
Input Method Panel

toupad

三指拖放:https://github.com/ferstar/gestures.git

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#https://blog.ferstar.org/posts/linux-touchpad-gestures-drag/
#https://github.com/ferstar/blog/issues/73
wget https://github.com/ferstar/gestures/releases/download/v0.8.2/gestures-linux-x86_64.tar.gz
tar zxvf gestures-linux-x86_64.tar.gz
sudo cp -a gestures-linux-x86_64/gestures /usr/local/bin/

sudo pacman -S libinput xdotool
yay -S ydotool

#Start ydotool Service
systemctl --user enable --now ydotool

# 1. Generate config file (first time only)
gestures generate-config

✓ Configuration file created at: /home/dave/.config/gestures.kdl

Edit the file to customize your gestures:
vim /home/dave/.config/gestures.kdl

After editing, reload the config:
gestures reload

View full documentation:
https://github.com/ferstar/gestures/blob/dev/config.md

# 2. Install service file
gestures install-service

# 3. Enable and start the service
systemctl --user enable --now gestures.service

#禁止休眠
# 一次性禁止所有休眠相关目标(sleep/suspend/hibernate/hybrid-sleep)
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
#恢复
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

#iso to usb
#https://etcher.balena.io/
yay -S balena-etcher

ssh

1
2
3
4
sudo pacman -S openssh
sudo sed -i 's;#PermitRootLogin.*;PermitRootLogin yes;g' /etc/ssh/sshd_config
sudo systemctl enable sshd
sudo systemctl start sshd

Securecrt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#https://www.cnblogs.com/amsilence/p/19151338
#https://github.com/amsilence/Linux-tools
yay --editmenu --editor=nano -S scrt
#把里面的source地址改为:https://eli.xir.no/VanDyke/scrt-9.6.4-3695.ubuntu24-64.x86_64.deb
git clone https://github.com/amsilence/Linux-tools.git
cd Linux-tools
#rm -fr /tmp/.securecrt.tmp
chmod +x ./securecrt_linux_crack.pl
sudo ./securecrt_linux_crack.pl /usr/bin/SecureCRT
#注册:替换VanDyke目前后再继续,不然还得重复注册
Name: ygeR
Company: TEAM ZWT
Serial Number: 03-38-361120
Issue Date: 10-19-2025
License Key: ACVG1Z 96MXM2 UP86HH UDGR4C ABKBJK 2NW3BH ZC23H5 GEWB7W

Remote Desktop

1
2
3
4
5
6
#向日葵
https://comate.baidu.com/zh/page/lbqpmkldtwh

#rustdesk
https://rustdesk.com/zh-cn/
https://github.com/rustdesk/rustdesk

NVM

1
2
3
4
5
6
7
8
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
. ~/.bashrc
#显示有远端的版本
#nvm ls-remote
#安装对应的版本
nvm install 12
nvm install 22
nvm alias default 22

Python Venv

1
2
3
4
5
6
7
#python -m venv /works/python_venv
#. /works/python_venv/bin/activate
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
#Python3.12
conda create --name py312 python=3.12
conda activate py312

waydroid

https://geek-blogs.com/blog/best-android-emulator-for-linux/

1
2
3
4
5
6
7
8
9
10
pip install dbus-python gbinder PyGObject
yay -S waydroid
sudo waydroid init -s GAPPS
sudo systemctl start waydroid-container
# 启动 Waydroid 图形界面
waydroid show-full-ui

#完全停止
waydroid session stop
sudo systemctl stop waydroid-container

Fix: This device isn’t Play Protect certified

1
2
3
#获取 Waydroid 的 Android ID(GSF ID)
sudo waydroid shell -- sh -c "sqlite3 /data/data/com.google.android.gsf/databases/gservices.db 'select value from main where name = \"android_id\";'"
#输出是一串长数字(比如 1234567890123456789),这就是你的 android_id。

在浏览器注册设备

1
2
3
4
5
6
7
8
9
10
11
12
13
打开任何浏览器(Manjaro 的 Firefox/Chrome 都行),访问:
https://www.google.com/android/uncertified
用你要登录 Play Store 的 同一个 Google 账号 登录。
输入刚才复制的 android_id(只复制数字,不要带 android_id|)。
完成 reCAPTCHA(可能要点图片验证)。
点击 Register。
页面会显示 “Device registered” 或类似(如果卡住不动,别慌,注册已成功)。

等待 + 清理缓存(关键步骤,很多坑在这里)
注册后 不要马上登录 Play Store,等 5-30 分钟(有时需几小时,Google 服务器同步慢)。
在 Waydroid 里:
去 设置 > 应用 > 查看所有应用 > Google Play Store → 强制停止 + 清除缓存 + 清除数据。
同上,对 Google Play Services 也清除缓存(别清数据,除非必要)。

重启 Waydroid:

1
2
3
waydroid session stop
sudo systemctl restart waydroid-container
waydroid show-full-ui

安装apk

1
2
waydroid session start
waydroid app install /path/to/your.apk

Samba

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
sudo pacman -Syu samba smbclient

#共享 /works/share 文件夹
sudo vim /etc/samba/smb.conf
[share]
comment = share
path = /works/share
browseable = yes
writable = yes
create mask = 0700
directory mask = 0700
valid users = dave

#创建共享目录并设置权限
mkdir -p /works/share
chmod 777 /works/share

#添加 Samba 用户
sudo smbpasswd -a $USER
# 启用该用户
sudo smbpasswd -e $USER

#禁用AppArmor
sudo aa-complain /usr/sbin/smbd

#启动并设置为开机自启
sudo systemctl enable --now smb

#检查状态
sudo systemctl status smb
# 检查配置文件是否有语法错误
testparm

#连接测试
smbclient //192.168.3.10/share -U dave

aria2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
yay -Syu aria2

mkdir -p /works/aria2 /works/aria2/Downloads
vim /works/aria2/aria2.conf
# 基本设置
dir=/works/aria2/Downloads
file-allocation=falloc
continue=true
allow-overwrite=true

# 速度与连接优化(根据你带宽调整)
max-concurrent-downloads=10
max-connection-per-server=16
min-split-size=1M
split=16

# RPC 设置(给 AriaNg、Motrix、手机App等前端用,必开)
enable-rpc=true
rpc-listen-all=true
rpc-listen-port=6800
rpc-secret=Aa123456
rpc-allow-origin-all=true

# BT相关(可选)
enable-dht=true
enable-peer-exchange=true
bt-enable-lpd=true
bt-max-peers=0
seed-ratio=0.0

# 其他优化
disk-cache=64M
http-accept-gzip=true
user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36

#测试启动
aria2c --conf-path=/works/aria2/aria2.conf

#做成 systemd服务
sudo nano /etc/systemd/system/aria2.service
[Unit]
Description=aria2 download utility
After=network.target

[Service]
Type=simple
User=dave
ExecStart=/usr/bin/aria2c --conf-path=/works/aria2/aria2.conf --log=/works/aria2/aria2.log
Restart=on-failure
RestartSec=5

[Install]
WantedBy=default.target

sudo systemctl daemon-reload
sudo systemctl enable --now aria2.service
sudo systemctl status aria2

# nano ~/.config/systemd/user/aria2.service
# systemctl --user daemon-reload
# systemctl --user enable --now aria2.service
# systemctl --user status aria2

#aria2-explorer
https://chromewebstore.google.com/detail/aria2-explorer/mpkodccbngfoacfalldjimigbofkhgjn?pli=1
系统设置->常规设置:配置对应的RPC即可

openwrt

安装后,配置好网络。DHCP/DNS -> 过滤器 -> 勾掉”重绑定保护”

中文包

1
2
3
4
5
6
7
8
OpenWRT -> System -> Software -> Filter
填入: luci-i18n-base-zh-cn

#timezone:
uci set system.@system[0].zonename='Asia/Shanghai'
uci set system.@system[0].timezone='CST-8'
uci commit system
/etc/init.d/system restart

theme-argon

参考以下文章安装主题:https://kwx.cc/post/3880

1
2
3
4
5
6
7
8
9
10
#https://github.com/jerrykuku/luci-theme-argon
#https://github.com/jerrykuku/luci-app-argon-config
wget https://github.com/jerrykuku/luci-theme-argon/releases/download/v2.3.2/luci-theme-argon_2.3.2-r20250207_all.ipk -O luci-theme-argon_2.3.2-r20250207_all.ipk

opkg update
opkg install luci-theme-argon_2.3.2-r20250207_all.ipk

#https://github.com/Openwrt-Passwall/openwrt-passwall /etc/config/passwall opkg install kmod-nft-socket
#https://github.com/lxiaya/openwrt-homeproxy /etc/config/homeproxy
#https://github.com/vernesong/openclash

救砖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
https://www.cnblogs.com/dingshaohua/p/18776622
https://www.cnblogs.com/dingshaohua/p/18821929
#安装CH340驱动:
https://telesky.yuque.com/bdys8w/01/qiyzczoxb58nrqx0

#下载openwrt-23.05.5-mediatek-filogic-xiaomi_mi-router-wr30u-ubootmod-initramfs-recovery.itb,必须23.05.5,24版本会报错
wget https://downloads.openwrt.org/releases/23.05.5/targets/mediatek/filogic/openwrt-23.05.5-mediatek-filogic-xiaomi_mi-router-wr30u-ubootmod-initramfs-recovery.itb
mv openwrt-23.05.5-mediatek-filogic-xiaomi_mi-router-wr30u-ubootmod-initramfs-recovery.itb openwrt-mediatek-filogic-xiaomi_mi-router-wr30u-ubootmod-initramfs-recovery.itb

#下载Tera Term
https://tera-term.en.softonic.com/
#配置:设置->串口:端口以电脑设备的串口号为准
端口: COM3
比特率:115200
先不要通电,接上usb to ttl的线,参考:https://www.cnblogs.com/dingshaohua/p/18776622
使用Tera Term连接,选择COM3,连接。然后再通电,进入uboot console:

成功进入 `MT7981>` 提示符,输入命令:
loadx 0x46000000
回车,uboot 等待接收文件。
然后 Tera Term 顶部菜单:
**文件 (F) → 传输 (T) → XMODEM → 发送 (S)**
- 选中你下载好的 openwrt-mediatek-filogic-xiaomi_mi-router-wr30u-ubootmod-initramfs-recovery.itb
会有进度条,时间会比较久,请耐心等待,完成后执行:
## 第 1 步:设置内存内环境变量(解决 FDT 内存报错,只本次生效)
setenv fdt_high 0xffffffff
setenv initrd_high 0xffffffff
直接复制粘贴到串口回车。
## 第 2 步:执行 bootm 启动内存 OpenWrt
bootm 0x46000000
回车执行!uboot 开始解析 FIT 镜像,打印内核启动日志,大量日志刷屏。
注意:openwrt基于内存,断电后失效。
完成后,网线插路由器**LAN**,电脑网卡静态 IP:`192.168.1.254/255.255.255.0`,就可以连接上openwrt了,然后登录openwrt web,在更新固件中,更新固件即可:
上传:openwrt-24.10.8-mediatek-filogic-xiaomi_mi-router-wr30u-ubootmod-squashfs-sysupgrade.itb,重启即可。

proxy+firewall失效

不能使用firewall的页面管理防火墙了,使用以下的脚本管理:

  1. 添加指定的mac地址:

    1
    2
    3
    4
    5
    6
    7
    8
    cat > /etc/nftables.d/99-reject-mac.nft << 'EOF'
    chain reject_mac_early {
    type filter hook prerouting priority mangle - 20; policy accept;
    ether saddr 08:26:AE:39:54:13 fib daddr type != local meta l4proto { tcp, udp } counter drop comment "block external traffic before homeproxy"
    }
    EOF

    fw4 reload
  2. 添加指定的ip地址:

    1
    2
    3
    4
    5
    6
    7
    8
    cat > /etc/nftables.d/99-reject-mac.nft << 'EOF'
    chain reject_mac_early {
    type filter hook prerouting priority mangle - 20; policy accept;
    ip saddr 192.168.8.100 fib daddr type != local meta l4proto { tcp, udp } counter drop comment "block IP 192.168.8.100"
    }
    EOF

    fw4 reload
  3. 添加mac+ip:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    cat > /etc/nftables.d/99-reject-mac.nft << 'EOF'
    chain reject_mac_early {
    type filter hook prerouting priority mangle - 20; policy accept;

    # MAC + IP 同时匹配才拦截
    ether saddr 08:26:AE:39:54:13 ip saddr 192.168.8.100 fib daddr type != local meta l4proto { tcp, udp } counter drop comment "block specific MAC+IP"
    }
    EOF

    fw4 reload
  4. 添加mac+time:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    cat > /etc/nftables.d/99-reject-mac.nft << 'EOF'
    chain reject_mac_early {
    type filter hook prerouting priority mangle - 20; policy accept;

    # 00:00-17:59 和 23:00-23:59 禁止
    ether saddr 08:26:AE:39:54:13 fib daddr type != local meta l4proto { tcp, udp } meta hour "00:00"-"17:59" counter drop comment "block outside allowed hours"
    ether saddr 08:26:AE:39:54:13 fib daddr type != local meta l4proto { tcp, udp } meta hour "23:00"-"23:59" counter drop comment "block outside allowed hours"
    ether saddr 08:26:AE:39:54:13 fib daddr type != local meta l4proto { tcp, udp } \
    meta day { Monday, Tuesday, Wednesday, Thursday, Friday } \
    meta hour "22:00"-"23:59" counter drop
    }
    EOF

    fw4 reload
  5. 验证:

    1
    2
    3
    4
    5
    6
    7
    nft list chain inet fw4 reject_mac_early
    table inet fw4 {
    chain reject_mac_early {
    type filter hook prerouting priority -170; policy accept;
    ether saddr 08:26:ae:39:54:13 fib daddr type != local meta l4proto { tcp, udp } counter packets 58 bytes 41170 drop comment "block external traffic before homeproxy"
    }
    }
  6. 删除:

    1
    2
    rm -f /etc/nftables.d/99-reject-mac.nft
    fw4 reload
  7. 完整脚本:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    cat > /root/proxy-block.sh << 'EOF'
    #!/bin/sh

    NFT_FILE="/etc/nftables.d/99-reject-mac.nft"
    CHAIN_NAME="reject_mac_early"

    RED='\033[0;31m'
    GREEN='\033[0;32m'
    YELLOW='\033[1;33m'
    BLUE='\033[0;34m'
    NC='\033[0m'

    print_header() {
    clear
    echo -e "${GREEN}========================================${NC}"
    echo -e "${GREEN} HomeProxy 外部流量拦截管理脚本${NC}"
    echo -e "${GREEN}========================================${NC}"
    }

    check_root() {
    if [ "$(id -u)" -ne 0 ]; then
    echo -e "${RED}请使用 root 用户运行此脚本${NC}"
    exit 1
    fi
    }

    reload_fw() {
    echo -e "${YELLOW}正在重新加载防火墙...${NC}"
    fw4 reload >/dev/null 2>&1
    if [ $? -eq 0 ]; then
    echo -e "${GREEN}防火墙已重新加载${NC}"
    else
    echo -e "${RED}防火墙加载失败,请检查规则语法${NC}"
    fi
    }

    show_current() {
    echo -e "\n${YELLOW}当前规则:${NC}"
    if [ -f "$NFT_FILE" ]; then
    echo -e "${BLUE}---------- nft 实际生效规则 ----------${NC}"
    nft list chain inet fw4 $CHAIN_NAME 2>/dev/null || echo "链未加载"
    echo -e "\n${BLUE}---------- 规则文件内容 ----------${NC}"
    cat "$NFT_FILE"
    else
    echo "当前没有拦截规则"
    fi
    }

    gen_header() {
    cat << HEADER
    chain $CHAIN_NAME {
    type filter hook prerouting priority mangle - 20; policy accept;

    HEADER
    }

    validate_mac() {
    local mac="$1"
    echo "$mac" | grep -Eq '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
    return $?
    }

    validate_time() {
    local time="$1"
    echo "$time" | grep -Eq '^([01][0-9]|2[0-3]):[0-5][0-9]$'
    return $?
    }

    parse_weekdays() {
    local input="$1"
    local result=""

    expanded=""
    for part in $(echo "$input" | tr ',' ' '); do
    if echo "$part" | grep -q '-'; then
    start=$(echo "$part" | cut -d'-' -f1)
    end=$(echo "$part" | cut -d'-' -f2)
    if ! echo "$start" | grep -Eq '^[1-7]$' || ! echo "$end" | grep -Eq '^[1-7]$'; then
    return 1
    fi
    i=$start
    while [ "$i" -le "$end" ]; do
    expanded="$expanded $i"
    i=$((i + 1))
    done
    else
    if ! echo "$part" | grep -Eq '^[1-7]$'; then
    return 1
    fi
    expanded="$expanded $part"
    fi
    done

    for d in $expanded; do
    case $d in
    1) name="Monday" ;;
    2) name="Tuesday" ;;
    3) name="Wednesday" ;;
    4) name="Thursday" ;;
    5) name="Friday" ;;
    6) name="Saturday" ;;
    7) name="Sunday" ;;
    *) continue ;;
    esac
    if [ -z "$result" ]; then
    result="$name"
    else
    result="$result, $name"
    fi
    done
    echo "$result"
    }

    add_rule() {
    local mac="$1"
    local ip="$2"
    local start_hour="$3"
    local end_hour="$4"
    local weekdays="$5"
    local comment="$6"

    match=""
    [ -n "$mac" ] && match="$match ether saddr $mac"
    [ -n "$ip" ] && match="$match ip saddr $ip"
    match="$match fib daddr type != local meta l4proto { tcp, udp }"

    comment_str=""
    if [ -n "$comment" ]; then
    comment_str=" comment \"$comment\""
    fi

    if [ -n "$start_hour" ] && [ -n "$end_hour" ]; then
    if [ -n "$weekdays" ]; then
    echo " ${match} meta day { $weekdays } meta hour \"${start_hour}\"-\"${end_hour}\" counter drop${comment_str}"
    else
    echo " ${match} meta hour \"${start_hour}\"-\"${end_hour}\" counter drop${comment_str}"
    fi
    else
    echo " ${match} counter drop${comment_str}"
    fi
    }

    write_rules() {
    local content="$1"
    if [ -z "$(echo -e "$content" | sed '/^$/d')" ]; then
    rm -f "$NFT_FILE"
    echo -e "${YELLOW}规则已全部清空${NC}"
    else
    gen_header > "$NFT_FILE"
    echo -e "$content" >> "$NFT_FILE"
    echo "}" >> "$NFT_FILE"
    fi
    reload_fw
    show_current
    }

    get_rule_lines() {
    if [ ! -f "$NFT_FILE" ]; then
    return
    fi
    sed -n '/type filter/,/^}/p' "$NFT_FILE" | sed '1d;$d' | grep -E '^[[:space:]]*(ether|ip)[[:space:]]' | sed 's/^[[:space:]]*//'
    }

    print_numbered() {
    local i=1
    echo "$1" | while read -r line; do
    printf "%2d. %s\n" "$i" "$line"
    i=$((i + 1))
    done
    }

    confirm_action() {
    echo -e "\n${YELLOW}请确认以上操作 (Y/n):${NC}"
    read -p "> " confirm
    if [ -z "$confirm" ] || [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
    return 0
    else
    echo -e "${RED}已取消操作${NC}"
    return 1
    fi
    }

    menu_add() {
    echo -e "\n${YELLOW}【添加拦截规则】${NC}"
    echo "1. 仅 MAC"
    echo "2. 仅 IP"
    echo "3. MAC + IP"
    read -p "请选择类型 [1-3]: " type

    mac=""
    ip=""
    case $type in
    1)
    while true; do
    read -p "请输入 MAC 地址 (例如 08:26:AE:39:54:13): " mac
    if validate_mac "$mac"; then
    break
    else
    echo -e "${RED}MAC 地址格式错误,请重新输入(示例:08:26:AE:39:54:13)${NC}"
    fi
    done
    ;;
    2)
    read -p "请输入 IP 地址 (例如 192.168.8.100): " ip
    ;;
    3)
    while true; do
    read -p "请输入 MAC 地址: " mac
    if validate_mac "$mac"; then
    break
    else
    echo -e "${RED}MAC 地址格式错误,请重新输入(示例:08:26:AE:39:54:13)${NC}"
    fi
    done
    read -p "请输入 IP 地址: " ip
    ;;
    *) echo -e "${RED}无效选择${NC}"; return ;;
    esac

    # 新增:输入 comment(可为空)
    read -p "请输入备注 comment(可直接回车为空): " comment

    echo -e "\n时间控制(填写【禁止】的时间段):"
    echo "1. 全天禁止"
    echo "2. 指定禁止时段 + 星期"
    read -p "请选择 [1-2]: " time_type

    rules=""
    case $time_type in
    1)
    rules=$(add_rule "$mac" "$ip" "" "" "" "$comment")
    ;;
    2)
    while true; do
    read -p "禁止开始时间 (HH:MM,例如 00:00): " start
    if validate_time "$start"; then
    break
    else
    echo -e "${RED}时间格式错误,请输入 HH:MM(00:00 - 23:59)${NC}"
    fi
    done

    while true; do
    read -p "禁止结束时间 (HH:MM,例如 08:00): " end
    if validate_time "$end"; then
    break
    else
    echo -e "${RED}时间格式错误,请输入 HH:MM(00:00 - 23:59)${NC}"
    fi
    done

    echo ""
    echo "星期设置说明:"
    echo " 1=周一 2=周二 3=周三 4=周四 5=周五 6=周六 7=周日"
    echo " 示例: 1,3,5 或 1-5 或 1-3,5,7"
    echo " 留空表示每天"
    read -p "请输入要禁止的星期 (直接回车=每天): " day_input

    weekdays=""
    if [ -n "$day_input" ]; then
    weekdays=$(parse_weekdays "$day_input")
    if [ -z "$weekdays" ]; then
    echo -e "${RED}星期格式错误,请重新添加规则${NC}"
    return
    fi
    fi
    rules=$(add_rule "$mac" "$ip" "$start" "$end" "$weekdays" "$comment")
    ;;
    *) echo -e "${RED}无效选择${NC}"; return ;;
    esac

    echo -e "\n${BLUE}即将添加的规则:${NC}"
    echo "$rules"
    if ! confirm_action; then
    return
    fi

    old_content=$(get_rule_lines)
    if [ -n "$old_content" ]; then
    new_content="${old_content}
    ${rules}"
    else
    new_content="$rules"
    fi

    write_rules "$new_content"
    echo -e "${GREEN}规则已添加并生效${NC}"
    }

    menu_delete_one() {
    echo -e "\n${YELLOW}【清除指定拦截规则】${NC}"

    if [ ! -f "$NFT_FILE" ]; then
    echo "当前没有任何规则"
    return
    fi

    lines=$(get_rule_lines)
    if [ -z "$lines" ]; then
    echo "当前没有任何规则"
    return
    fi

    echo -e "${BLUE}当前规则列表:${NC}"
    print_numbered "$lines"

    total=$(echo "$lines" | wc -l)
    echo ""
    read -p "请输入要删除的规则序号 (1-$total,多个用空格分隔,输入 all 删除全部): " input

    if [ -z "$input" ]; then
    echo -e "${RED}你没有输入任何序号,操作已取消${NC}"
    return
    fi

    if [ "$input" = "all" ] || [ "$input" = "ALL" ]; then
    echo -e "\n${YELLOW}即将删除【全部】规则${NC}"
    if ! confirm_action; then
    return
    fi
    rm -f "$NFT_FILE"
    reload_fw
    echo -e "${GREEN}已删除全部规则${NC}"
    return
    fi

    valid=0
    for num in $input; do
    if [ "$num" -ge 1 ] 2>/dev/null && [ "$num" -le "$total" ] 2>/dev/null; then
    valid=1
    break
    fi
    done
    if [ $valid -eq 0 ]; then
    echo -e "${RED}输入的序号无效,操作已取消${NC}"
    return
    fi

    echo -e "\n${BLUE}即将删除以下规则:${NC}"
    i=1
    echo "$lines" | while read -r line; do
    for num in $input; do
    if [ "$i" -eq "$num" ]; then
    echo " $i. $line"
    fi
    done
    i=$((i + 1))
    done

    if ! confirm_action; then
    return
    fi

    i=1
    echo "$lines" | while read -r line; do
    delete=0
    for num in $input; do
    if [ "$i" -eq "$num" ]; then
    delete=1
    break
    fi
    done
    if [ $delete -eq 0 ]; then
    echo "$line"
    fi
    i=$((i + 1))
    done > /tmp/proxy_block_new.rules

    new_content=$(cat /tmp/proxy_block_new.rules 2>/dev/null)
    rm -f /tmp/proxy_block_new.rules

    write_rules "$new_content"
    echo -e "${GREEN}指定规则已删除${NC}"
    }

    menu_clear() {
    echo -e "\n${YELLOW}即将删除【所有】拦截规则${NC}"
    if ! confirm_action; then
    return
    fi
    rm -f "$NFT_FILE"
    reload_fw
    echo -e "${GREEN}所有拦截规则已清除${NC}"
    }

    main_menu() {
    while true; do
    print_header
    echo "1. 查看当前规则"
    echo "2. 添加拦截规则(MAC / IP / 时间)"
    echo "3. 清除指定拦截规则"
    echo "4. 清除所有拦截规则"
    echo "5. 手动重新加载防火墙"
    echo "0. 退出"
    echo "----------------------------------------"
    read -p "请选择操作 [0-5]: " choice

    case $choice in
    1) show_current ;;
    2) menu_add ;;
    3) menu_delete_one ;;
    4) menu_clear ;;
    5) reload_fw ;;
    0) echo "退出"; exit 0 ;;
    *) echo -e "${RED}无效选择${NC}" ;;
    esac

    echo ""
    read -p "按回车键继续..."
    done
    }

    check_root
    main_menu
    EOF

    chmod +x /root/proxy-block.sh

ocserv

1
2
3
4
5
6
7
8
opkg update
opkg install ocserv luci-app-ocserv luci-i18n-ocserv-zh-cn

##vim /etc/sysctl.conf
#net.ipv4.ip_forward=1
#net.ipv4.conf.all.proxy_arp=1

#sysctl -p

通用配置:

1
2
3
4
用户身份验证: plan
端口: 443
VPN IPv4–网络地址: 192.168.4.1
DNS 服务器: 223.5.5.5

用户设置中配置账户信息即可。

配置vpns+规则:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
进入:网络->防火墙->常规设置:

#路由器模式:
#wan/lan:
"入站数据 出站数据 区域内转发":都接受,勾选“IP 动态伪装“
#lan: 编辑:
高级设置:覆盖的设备:vpns+ 地址族限制:仅IPv4
#防火墙 - 通信规则:
名称:Allow-Ocserv,源区域: wan 目标端口: 14443 操作:接受

#旁路由模式:
#lan:
"入站数据 出站数据 区域内转发":都接受,勾选“IP 动态伪装“
#lan: 编辑:
高级设置:覆盖的设备:vpns+ 地址族限制:仅IPv4
#防火墙 - 通信规则(旁路由模式):
名称:Allow-Ocserv,源区域: lan 目标端口: 14443 操作:接受

配置其他网段的route:

1
2
3
4
5
6
7
8
9
10
11
12
13
#vim /etc/config/ocserv

config routes
option ip '192.168.111.0/24'
option netmask '255.255.255.0'

config routes
option ip '192.168.112.0/24'
option netmask '255.255.255.0'
......

#重启
/etc/init.d/ocserv restart

ssl证书:

1
2
3
4
5
6
7
8
9
#VPN->OpenConect VPN->编辑模板:
server-cert = /data/ocserv/ssl/xxxx.net.pem
server-key = /data/ocserv/ssl/xxxx.net.key
#提交并重启
/etc/init.d/ocserv restart

#blog的备份文件:backup/vpn/ocserv.zip

手机openconnect后,dns无效时,把DNS从8.8.8.8改为223.5.5.5即可

Proxmox

安装debain 13

1
2
3
4
5
6
7
#下载debain
#https://www.debian.org/CD/http-ftp/
#https://mirror.lzu.edu.cn/debian-cd/13.3.0/
wget https://mirror.lzu.edu.cn/debian-cd/13.3.0/amd64/iso-dvd/debian-13.3.0-amd64-DVD-1.iso
#正常安装系统
#设置时区
timedatectl set-timezone Asia/Shanghai

安装Proxmox 9

1
2
3
4
5
6
7
#安装Proxmox 9 on debain 13,按照以下文档安装即可
#https://pve.proxmox.com/wiki/Install_Proxmox_VE_on_Debian_13_Trixie

#Connect to the Proxmox VE Web Interface
Connect to the admin web interface (https://your-ip-address:8006).
If you have a fresh install and have not added any users yet, you should select PAM authentication realm
and login with root user account.

创建网桥

Create a Linux Bridge called vmbr0, and add your first network interface to it.

The recommended default configuration can be adapted from the example given in the documentation.
See the default configuration using a bridge:
https://pve.proxmox.com/wiki/Network_Configuration#_default_configuration_using_a_bridge

编辑文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
vim /etc/network/interfaces:

auto lo
iface lo inet loopback

iface enp1s0 inet manual
iface enp2s0 inet manual
iface wlo1 inet manual

auto vmbr0
iface vmbr0 inet static
address 192.168.3.10/24
#gateway 192.168.3.1
bridge-ports enp1s0
#dns-nameservers 223.5.5.5 8.8.8.8
bridge-stp off
bridge-fd 0

post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '192.168.3.0/24' -o vmbr0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '192.168.3.0/24' -o vmbr0 -j MASQUERADE

auto vmbr1
iface vmbr1 inet static
address 192.168.1.2/24
gateway 192.168.1.1
bridge-ports enp2s0
bridge-stp off
bridge-fd 0

post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s '192.168.3.0/24' -o vmbr1 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '192.168.3.0/24' -o vmbr1 -j MASQUERADE

#重新加载:
apt install ifupdown2
ifreload -a
# 或
systemctl restart networking

安装CT

1
2
3
4
5
6
7
8
#https://mirrors.ustc.edu.cn/help/proxmox.html
#https://prox4-rs5.gd.ddnsto.com/pve-docs/chapter-pct.html#pct_container_images
pveam update
pveam available

#安装ubuntu 24
pveam download local ubuntu-24.04-standard_24.04-2_amd64.tar.zst
pveam list local

宿主机进入容器:

1
2
3
4
5
6
7
8
9
#在web界面安装好后,宿主机进入容器
> pct enter <容器id>
nano /etc/ssh/sshd_config
# 找到 PermitRootLogin,修改为:
PermitRootLogin yes
# 重启服务
systemctl restart ssh

#配置文件位于宿主机:nano /etc/pve/lxc/<ct-id>.conf

Openwrt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#https://downloads.openwrt.org/releases/25.12.0/targets/x86/64/
cd /var/lib/vz/template/cache/
#wget https://downloads.openwrt.org/releases/25.12.0/targets/x86/64/openwrt-25.12.0-x86-64-rootfs.tar.gz
wget https://downloads.openwrt.org/releases/24.10.5/targets/x86/64/openwrt-24.10.5-x86-64-rootfs.tar.gz

pct create 100 /var/lib/vz/template/cache/openwrt-24.10.5-x86-64-rootfs.tar.gz \
--arch amd64 \
--hostname OpenWrt-24.10 \
--rootfs local:1 \
--memory 512 \
--cores 1 \
--ostype unmanaged \
--net0 name=eth0,bridge=vmbr0,ip=192.168.3.3/24,gw=192.168.3.1 \
--unprivileged 0

#在web界面安装好后,宿主机进入容器:安装后IP有些问题,需要手动进入容器改一下IP
> pct enter <容器id>
vi /etc/config/network
...
config interface 'lan'
option device 'br-lan'
option proto 'static'
option ipaddr '192.168.3.1'
option netmask '255.255.255.0'
option gateway '192.168.3.10'
option ip6assign '60'
option multipath 'off'

#或者带wan+zerotier的配置:
config interface 'lan'
option device 'br-lan'
option proto 'static'
option multipath 'off'
option peerdns '0'
list dns '223.5.5.5'
list dns '8.8.8.8'
list ipaddr '192.168.3.1/24'

config interface 'wan'
option proto 'static'
option device 'eth1'
option ipaddr '192.168.1.3'
option netmask '255.255.255.0'
option gateway '192.168.1.1'

config route
option interface 'lan'
option target '192.168.195.0/24'
option gateway '192.168.3.10'

#/etc/resolv.conf是软链,不能被修改,需要删除重建
# 删除现有的软链接
rm /etc/resolv.conf

# 创建一个真实的普通文件并写入你的 DNS
cat <<EOF > /etc/resolv.conf
search lan
nameserver 223.5.5.5
nameserver 8.8.8.8
EOF

#homeproxy别名
vim ~/.profile
alias ss="/etc/init.d/homeproxy start"
alias tt="/etc/init.d/homeproxy stop"

...
#reboot
pct stop <容器id>
pct start <容器id>

Proxmox 9.x由于ujail限制,homeporxy无法启动,需要修改宿主机的配置:
nano /etc/pve/lxc/104.conf

1
2
3
4
5
6
unprivileged: 0
lxc.cgroup2.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
lxc.mount.auto: proc:rw sys:rw
lxc.cap.drop:
lxc.apparmor.profile: unconfined

重启CT容器后生效。

如果需要前移旧设备的信息的话,可以把以下的三个文件里面的内容复制过去:

1
2
3
4
5
6
#可以直接覆盖
/etc/config/homeproxy
#复制里面的静态ip部分
/etc/config/dhcp
#复制里面的防火墙部分
/etc/config/firewall

解决openwrt作为路由器时,ip能ping通,当域名不能的问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 给 WAN 接口强制指定上游 DNS(如果接口名不是 wan,请改成实际名字)
uci set network.lan.peerdns='0'
uci delete network.lan.dns
uci add_list network.lan.dns='223.5.5.5'
uci add_list network.lan.dns='8.8.8.8'

# 同时让 dnsmasq 也使用这些 DNS
uci set dhcp.@dnsmasq[0].noresolv='0'
uci delete dhcp.@dnsmasq[0].server
uci add_list dhcp.@dnsmasq[0].server='223.5.5.5'
uci add_list dhcp.@dnsmasq[0].server='8.8.8.8'

uci commit network
uci commit dhcp
/etc/init.d/network restart
/etc/init.d/dnsmasq restart

ZeroTier

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#https://github.com/mwarning/zerotier-openwrt/wiki/Configure-ZeroTier-on-OpenWrt
#Installation
opkg update
opkg install zerotier
#Configure ZeroTier on your OpenWrt router
uci set zerotier.global.enabled='1'
uci delete zerotier.earth
uci set zerotier.openwrt_network=network
uci set zerotier.openwrt_network.id='<your-network-id>'
uci commit zerotier

reboot

#Make sure you Authorize the client

#Open OpenWrt Firewall for ZeroTier Incoming Connections
uci add firewall rule
uci set firewall.@rule[-1].name='Allow-ZeroTier-Inbound'
uci set firewall.@rule[-1].src='*'
uci set firewall.@rule[-1].target='ACCEPT'
uci set firewall.@rule[-1].proto='udp'
uci set firewall.@rule[-1].dest_port='9993'
uci commit firewall

/etc/init.d/firewall restart

#https://github.com/mwarning/zerotier-openwrt/wiki/Configure-ZeroTier-routing-in-OpenWrt
#Configure ZeroTier routing in OpenWrt
# Create interface
uci set network.ZeroTier=interface
uci set network.ZeroTier.proto='none'
uci set network.ZeroTier.device='ztXXXXXXXX' # Replace ztXXXXXXXX with your own ZeroTier interface name

# Create zone
uci add firewall zone
uci set firewall.@zone[-1].name='vpn'
uci set firewall.@zone[-1].input='ACCEPT'
uci set firewall.@zone[-1].output='ACCEPT'
uci set firewall.@zone[-1].forward='ACCEPT'
uci set firewall.@zone[-1].masq='1'
uci add_list firewall.@zone[-1].network='ZeroTier'
uci add firewall forwarding
uci set firewall.@forwarding[-1].src='vpn'
uci set firewall.@forwarding[-1].dest='lan'
uci add firewall forwarding
uci set firewall.@forwarding[-1].src='vpn'
uci set firewall.@forwarding[-1].dest='wan'
uci add firewall forwarding
uci set firewall.@forwarding[-1].src='lan'
uci set firewall.@forwarding[-1].dest='vpn'

# Commit changes
uci commit

/etc/init.d/firewall restart

如果openwrt采取的是lan+wan的方式的话,从宿主机无法访问到openwrt的解决方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#openwrt添加路由(推荐)
# 让 OpenWRT 知道 192.168.195.0/24 要走宿主机
#ip route add 192.168.195.0/24 via 192.168.3.10
# 永久生效(写入配置)
uci add network route
uci set network.@route[-1].interface='lan'
uci set network.@route[-1].target='192.168.195.0/24'
uci set network.@route[-1].gateway='192.168.3.10'
uci commit network
/etc/init.d/network restart

#可选:或者在宿主机配置, vmbr0为内网口:
# 把从 ZeroTier 进来、去往 192.168.3.0/24 的流量伪装成主机自己的 IP
iptables -t nat -A POSTROUTING -s 192.168.195.0/24 -d 192.168.3.0/24 -o vmbr0 -j MASQUERADE
# 或者更宽一点:
#iptables -t nat -A POSTROUTING -o vmbr0 -j MASQUERADE
#持久化
apt install -y iptables-persistent
iptables-save > /etc/iptables/rules.v4
# 或
netfilter-persistent save

Arch linux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#http://download.proxmox.com
cd /var/lib/vz/template/cache/
wget http://download.proxmox.com/images/system/archlinux-base_20240911-1_amd64.tar.zst
# 或用镜像:https://images.linuxcontainers.org/
wget https://images.linuxcontainers.org/images/archlinux/current/amd64/default/20260310_04:18/rootfs.tar.xz
# 重命名成更易认的(Proxmox 会显示这个名字)
mv rootfs.tar.xz archlinuxarm-amd64-latest.tar.gz

#arm64
wget http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz

#配置:
cd /etc/systemd/network/,删除无用的network配置,否则ip获取错误。
#DisableSandbox
#打开配置文件:
nano /etc/pacman.conf
找到 [options] 部分,添加:
DisableSandbox
#Upgrade:
pacman-key --init
pacman-key --populate archlinuxarm
pacman -Sy archlinux-keyring
pacman -Syu

#安装yay
nano /etc/pve/lxc/102.conf
features: nesting=1
lxc.cap.drop:
# 安装 sudo(如果还没装)
pacman -Syu sudo
# 创建新用户(例如叫 builduser)
useradd -m dave
passwd dave
# 将用户加入 wheel 组并允许 sudo
# 使用 visudo 去掉 '%wheel ALL=(ALL:ALL) ALL' 前面的注释
echo 'dave ALL=(ALL:ALL) ALL' >> /etc/sudoers
# 切换到该用户
su - dave
pacman -S --needed git base-devel
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

Ubuntu arm64

1
2
3
#https://github.com/jiangcuo/pxvirt/issues/174
#https://jenkins.linuxcontainers.org/job/image-ubuntu/
wget -O "ubuntu-noble-20250409_arm64.tar.xz" "https://jenkins.linuxcontainers.org/job/image-ubuntu/architecture=arm64,release=noble,variant=default/lastSuccessfulBuild/artifact/rootfs.tar.xz"