OpenWrt/Backup & Upgrade

OpenWrt/Backup & Upgrade

Web UI - System - Backup / Flash Firmware: Generate archive, 将导出 OpenWrt root overlay 文件系统里的用户修改过的系统配置文件。

/etc/sysupgrade.conf

此文件定义 OpenWrt 升级时保留哪些目录文件。这些文件也会被(额外)包含在 OpenWrt export data 导出的压缩包里。

## This file contains files and directories that should
## be preserved during an upgrade.

/root/files
/root/.ssh
/root/.config
/root/.profile
/etc/config/zerotier
#/etc/crontabs/root

#/etc/rc.local
#/etc/firewall.user
#/etc/dnsmasq.conf

#/etc/config/dhcp

# symlink to /root/.ssh/authorized_keys
#/etc/dropbear/authorized_keys

Other packages :

# openclash 
/etc/openclash/core

恢复脚本

上传以下目录和文件,覆盖 OpenWrt 里相应路径

/root/files # 用户文件保存主目录
/root/.profile # shell 用户启动脚本

/root/.ssh # ssh 公钥、保存的会话等目录
/root/.config # 一些第三方 app (如 rclone)配置文件目录
/etc/crontabs/root # crontab 配置文件

执行脚本:

chmod a+x /root/files/scripts/*
chmod a+x /root/files/bin/*
ln -s /root/.ssh/authorized_keys  /etc/dropbear/authorized_keys

其它系统配置 (手动还原)

基本配置

LAN / WAN / 无线

/etc/config/network
/etc/config/wireless
uci set network.lan.netmask='255.255.254.0' # 设置 LAN 网段为 192.168.1.0/23 

系统脚本 / 配置文件

/etc/rc.local
/etc/firewall.user
/etc/dnsmasq.conf
/etc/hotplug.d/iface/60-custom

这几个 OpenWrt 系统配置文件内容推荐仅加入指向 /root/files/ 目录下的配置文件引用,以方便移植。

  • /etc/rc.local (启动脚本): 末尾加入一行 "/root/files/scripts/init.sh"
  • /etc/firewall.user (防火墙规则): 末尾加入一行 "/root/files/scripts/firewall.sh"
  • /etc/dnsmasq.conf (DNS规则): 末尾加入一行 "conf-file=/root/files/appdata/dnsmasq/dnsmasq.conf"
  • /etc/hotplug.d/iface/60-custom (网卡事件监听自定义脚本,新建): 内容只有一行 "/root/files/scripts/iface-hotplug.sh"

/etc/opkg.conf

默认内容:

dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
option check_signature

如果设备有 emmc / u盘等外置存储,可以在 /etc/opkg.conf 里增加配置 opkg 的安装目录(dest):

dest ext /mnt/emmc/rootfs

以上配置则 opkg install python3 -d ext 会将软件包安装到 /mnt/emmc/rootfs 目录(而不是 / )下。

/etc/config/dhcp

包括一些 DHCP 和网络配置。

uci set dhcp.@dnsmasq[0].rebind_protection='0'

对应配置文件

config dnsmasq
        option rebind_protection '0'

这里关闭 dnsmasq 的 rebind protection。其它的 dnsmasq 配置全部放在自定义的配置文件里。

另外还包含 OpenWrt Web 界面里配置的 DHCP 静态绑定信息(所有 "config host" 区块)。

重启 dnsmasq 服务生效。

/etc/config/firewall

定义 OpenWrt UI - Network - Firewall 里配置。推荐将大部分 iptables 配置放到自定义的 firewall.user 脚本里。这里需要修改 / 配置的地方:

uci set firewall.@defaults[0].syn_flood='0'
uci set firewall.@zone[0].masq='1'
uci set firewall.@zone[1].masq='1'
config defaults
        option syn_flood        0
        option forward          ACCEPT

config zone
        option name 'lan'
        option masq '1'

config zone
        option name 'wan'
        option masq '1'

等效于 UI 界面:

  • General Settings - Enable SYN-flood protection : 取消勾选
  • General Settings - Forward : 设为 Accept
  • General Settings - Zones - wan => ACCEPT : 勾选 Masquerading

smartdns

OpenWrt 官方仓库安装的 smartdns 包。

安装

opkg update
opkg install smartdns

配置

uci set smartdns.@smartdns[0].enabled='1'
uci set smartdns.@smartdns[0].port='6054'

注:(2022-03测试)由于某些问题,必须通过 uci 修改配置,直接修改 /etc/config/smartdns 无效。

修改 /etc/smartdns/custom.conf 加入一行 "conf-file /root/files/appdata/smartdns/smartdns.conf"

重启 smartdns 服务生效。

zerotier

安装

opkg update
opkg install zerotier

配置

uci set zerotier.openwrt_network.enabled='1'
uci set zerotier.openwrt_network.join='ffffffff'

重启 / 启动 zerotier 服务生效。更多参考 zerotier/OpenWrt


Last update: 2022-03-18 06:59:10 UTC