Skip to content

UCI 的命令行操作

shell
# Section
uci set config.section-name=section-type # 增加
uci rename config.section=name           # 改名
uci delete config.section                # 删除
# Option
uci set config.section.option=value # 增/改
uci get config.section.option       # 读取
uci delete config.section.option    # 删除
# List
uci add_list config.section.list=value # 增加值
uci get config.section.list            # 读取值
uci delete config.section.list         # 删除列表
uci del_list config.section.list=value # 删除值
# 展示
uci export config.section

定位语法

  • 存在同类无名配置节:@配置节类型[索引]
  • 同类配置节都有名称:配置节类型.配置节名称

索引从0开始计数.


操作服务

shell
/etc/init.d/example stop # 停止服务
/etc/init.d/example start # 启动服务
/etc/init.d/example enable # 开机启动
/etc/init.d/example disable # 禁止 开机启动

选择v6 IP

由于IP v6地址经常变化,所以很难基于IP设置流量规则。但是利用v6 IP 的后64位固定、反掩码,就可以筛选出特定的设备。

下面的例子就代表,只要v6 IP的后64位匹配,就会被选中。

shell
::42:c0ff:fea8:51a/::ffff:ffff:ffff:ffff

恢复出厂设置

shell
firstboot

修改模块“网络检测”的默认域名

修改此文件的相关变量。

shell
vim /etc/config/luci
groovy
config internal 'diag'
	option dns 'openwrt.org'
	option ping 'openwrt.org'
	option route 'openwrt.org'

免密码SSH连接

客户端发送公钥到 OpenWRT

shell
ssh root@192.168.5.1 "tee -a /etc/dropbear/authorized_keys" < ~/.ssh/id_rsa.pub

客户端配置别名(可选)。在~/.ssh/config增加此块

ini
# router
Host openwrt
	User root
	HostName 192.168.5.1
    # IdentityFile ~/.ssh/id_rsa.pub

获取当前公网IP

shell
ip -4 addr show pppoe-wan | grep inet | awk '{print $2}' | cut -d/ -f1 # IP v4
ip -6 addr show pppoe-wan | grep inet6 | grep -v fe80 | awk '{print $2}' | cut -d/ -f1 # IP v6