OpenWrt uci增加一个section

本文详细介绍了如何使用UCI命令在OpenWrt中进行配置文件管理,包括创建、添加节点、删除节点以及统计section数量。通过示例展示了如何操作firewall规则,并提到了uciset、ucidel和ucishow等关键命令的应用。
摘要由CSDN通过智能技术生成
1.说明:<config> 指配置文件名,如dhcp,firewall,fstab等
  uci set <config>.<section>=<section-type> 增加一个节点到文件中
  uci set <config>.<section>.<option>=<value> 增加一个选项和值到节点中
  uci add_list <config>.<section>.<option>=<value> 增加一个值到列表中

2.示例
  touch /etc/config/test //创建一个配置文件test
  uci set test.first=config //创建一个节点first
  uci set test.first.name='abc' //添加option name及值'abc'
  uci show test //显示配置文件test里的内容
  #test.first=config
  #test.first.name='abc'
  uci commit //保存配置文件test
3.新增节点:   uci set firewall.test=rule # 这里是新增test section,注意是set而不是add
  uci add_list firewall.test.icmp_type='router-advertisement'   uci set firewall.test.target='DROP'   uci set firewall.test.src='wan'   uci set firewall.test.proto='icmp'   uci set firewall.test.family='ipv6'   uci commit firewall 4.删除节点   uci del firewall.test

5.统计同一<section-type>的分区个数
  uci set <config>.<section>=<section-type>
  <section-type>可以自定义名字
  root@OpenWrt:~# touch /etc/config/op_station
  root@OpenWrt:~# uci set op_station.1=station
  root@OpenWrt:~# uci set op_station.2=station
  root@OpenWrt:~# uci set op_station.1.mac='11:22:33:44:55:66'
  root@OpenWrt:~# uci set op_station.2.mac='12:22:33:44:55:66'
  root@OpenWrt:~# uci show op_station
  op_station.1=station
  op_station.1.mac='11:22:33:44:55:66'
  op_station.2=station
  op_station.2.mac='12:22:33:44:55:66'
  root@OpenWrt:~# uci commit op_station
  root@OpenWrt:~# uci show op_station | grep -w station | wc -l
  2
  root@OpenWrt:~# cat /etc/config/op_station
  config station '1'
        option mac '11:22:33:44:55:66'
  config station '2'
        option mac '12:22:33:44:55:66'

参考:https://blog.csdn.net/m0_37922443/article/details/103006846

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值