Openwrt笔记---UCI

UCI是什么?

The abbreviation UCI stands for Unified Configuration Interface, and is a system to centralize the configuration of OpenWrt services.

Configuration files

FileDescription
Basic
/etc/config/dhcpDnsmasq and odhcpd settings: DNS, DHCP, DHCPv6
/etc/config/dropbearSSH server options
/etc/config/firewallNAT, packet filter, port forwarding, etc.
/etc/config/networkSwitch, interface and route configuration:
GeneralIPv4IPv6RoutesRulesWANAliasesSwitchesVLANIPv4/IPv6 transitioningTunneling
/etc/config/systemMisc. system settings, NTPRNGWatchcat
/etc/config/wirelessWireless settings and wifi network definition
IPv6
/etc/config/ahcpdAd-Hoc Configuration Protocol (AHCP) server and forwarder configuration
/etc/config/dhcp6cWIDE-DHCPv6 client
/etc/config/dhcp6sWIDE-DHCPv6 server
/etc/config/gw6cGW6c client configuration
Other
/etc/config/babeldbabeld configuration
/etc/config/bbstoredBoxBackup server configuration
/etc/config/ddnsDynamic DNS configuration (ddns-scripts)
/etc/config/dnscrypt-proxyDNSCrypt proxy
/etc/config/dockerdThe Docker CE Engine Daemon
/etc/config/emailrelayE-MailRelay: simple SMTP server and proxy with POP support. Package emailrelay
/etc/config/etherwakeWake-on-Lan: etherwake
/etc/config/freifunk_p2pblockUses iptables layer7-, ipp2p- and recent-modules to block p2p/filesharing traffic
/etc/config/fstabMount points and swap
/etc/config/hd-idleAnother idle-daemon for attached hard drives
/etc/config/httpdWeb server options (Busybox httpd, deprecated)
/etc/config/ipset-dnsConfigure ipset-dns
/etc/config/kadnodeKadNode p2p DNS
/etc/config/luciBase LuCI config
/etc/config/luci_statisticsConfiguration of Statistics packet
/etc/config/mini_snmpdmini_snmpd settings
/etc/config/minidlnaMiniDLNA settings
/etc/config/mjpg-streamerStreaming application for Linux-UVC compatible webcams
/etc/config/mountdOpenWrt automount daemon
/etc/config/mrouteConfiguration files for multiple WAN routes
/etc/config/multiwanSimple multi WAN configuration
/etc/config/mwan3Multi-WAN config with load balancing and failover
/etc/config/nodogsplashnodogsplash configuration
/etc/config/ntpclientGetting the correct time
/etc/config/nut_serverControlling a UPS (Uninterruptible Power Supply) and/or sharing with other hosts
/etc/config/nut_monitorMonitoring a UPS (Uninterruptible Power Supply) from a remote host or local nut-server
/etc/config/nut_cgiWeb UI for NUT (viewing only in UCI)
/etc/config/p910ndconfig for non-spooling Printer daemon p910nd.server
/etc/config/pure-ftpdPure-FTPd server config
/etc/config/qosImplementing Quality of Service for the upload
/etc/config/racoonracoon IPsec daemon
/etc/config/sambasettings for the Microsoft file and print services daemon
/etc/config/snmpdSNMPd settings
/etc/config/sqmSQM settings
/etc/config/sshtunnelSettings for the package sshtunnel
/etc/config/stundSTUN server configuration
/etc/config/tinctinc package configuration
/etc/config/torTor configuration
/etc/config/tor-hsTor hidden services configuration
/etc/config/transmissionBitTorrent configuration
/etc/config/uhttpdWeb server options (uHTTPd)
/etc/config/upnpdminiupnpd UPnP server settings
/etc/config/usersuser database for different services
/etc/config/ushareuShare UPnP server settings
/etc/config/vbladevblade userspace AOE target
/etc/config/vnstatvnstat downloader settings
/etc/config/wifitoggleToggle WiFi with a button
/etc/config/wolWake-on-Lan: wol
/etc/config/zncZNC bouncer configuration

举例子

# uci
Usage: uci [<options>] <command> [<arguments>]

Commands:
	batch
	export     [<config>]
	import     [<config>]
	changes    [<config>]
	commit     [<config>]
	add        <config> <section-type>
	add_list   <config>.<section>.<option>=<string>
	del_list   <config>.<section>.<option>=<string>
	show       [<config>[.<section>[.<option>]]]
	get        <config>.<section>[.<option>]
	set        <config>.<section>[.<option>]=<value>
	delete     <config>.<section>[.<option>]
	rename     <config>.<section>[.<option>]=<name>
	revert     <config>[.<section>[.<option>]]
	reorder    <config>.<section>=<position>

Options:
	-c <path>  set the search path for config files (default: /etc/config)
	-d <str>   set the delimiter for list values in uci show
	-f <file>  use <file> as input instead of stdin
	-m         when importing, merge data into an existing package
	-n         name unnamed sections on export (default)
	-N         don't name unnamed sections
	-p <path>  add a search path for config change files
	-P <path>  add a search path for config change files and use as default
	-q         quiet mode (don't print error messages)
	-s         force strict mode (stop on parser errors, default)
	-S         disable strict mode
	-X         do not use extended syntax on 'show'
Command Target Description 
commit[<config>]Writes changes of the given configuration file, or if none is given, all configuration files, to the filesystem. All “uci set”, “uci add”, “uci rename” and “uci delete” commands are staged into a temporary location and written to flash at once with “uci commit”. This is not needed after editing configuration files with a text editor, but for scripts, GUIs and other programs working directly with UCI files.
batch-Executes a multi-line UCI script which is typically wrapped into a here document syntax.
export[<config>]Exports the configuration in a machine readable format. It is used internally to evaluate configuration files as shell scripts.
import[<config>]Imports configuration files in UCI syntax.
changes[<config>]List staged changes to the given configuration file or if none given, all configuration files.
add<config> <section-type>Add an anonymous section of type section-type to the given configuration.
add_list<config>.<section>.<option>=<string>Add the given string to an existing list option.
del_list<config>.<section>.<option>=<string>Remove the given string from an existing list option.
show[<config>[.<section>[.<option>]]]Show the given option, section or configuration in compressed notation.
get<config>.<section>[.<option>]Get the value of the given option or the type of the given section.
set<config>.<section>[.<option>]=<value>Set the value of the given option, or add a new section with the type set to the given value.
delete<config>.<section>[.<option>]Delete the given section or option.
rename<config>.<section>[.<option>]=<name>Rename the given option or section to the given name.
revert<config>[.<section>[.<option>]]Revert the given option, section or configuration file.
reorder<config>.<section>=<position>Move a section to another position.

UCI配置实例(以MT7628开发板为例)

配置switch和vlan mt7628开发板有五个网口port0~port4 实际开发板仅仅引出三个网口,这里计划port0作为wan口 ,port1 port2 作为lan口

#使能vlan功能

uci add network switch
uci set network.@switch[0].name=switch0
uci set network.@switch[0].reset=1
uci set network.@switch[0].enable_vlan=1
uci commit

# 设置vlan1 port 0 后面作为wan口
uci add network switch_vlan
uci set network.@switch_vlan[0].device=switch0
uci set network.@switch_vlan[0].vlan=1
uci set network.@switch_vlan[0].ports='0 6t'
uci commit

# 设置vlan2 port 1 2 后面作为lan口
uci add network switch_vlan
uci set network.@switch_vlan[1].device=switch0
uci set network.@switch_vlan[1].vlan=2
uci set network.@switch_vlan[1].ports='1 2 6t'


####设置网桥
uci add network device
uci set network.@device[0].name=br-lan
uci set network.@device[0].type=bridge
uci add_list network.@device[0].ports=eth0.2

###设置lan口信息
uci set network.lan=interface
uci set network.lan.device=br-lan
uci set network.lan.proto=static
uci set network.lan.ipaddr=192.168.56.1
uci set network.lan.netmask=255.255.255.0

###设置wan口信息

uci set network.wan=interface
uci set network.wan.device=eth0.1
uci set network.wan.proto=dhcp
uci commit



root@openwrt:/# uci show network
network.loopback=interface
network.loopback.device='lo'
network.loopback.proto='static'
network.loopback.ipaddr='127.0.0.1'
network.loopback.netmask='255.0.0.0'
network.globals=globals
network.globals.ula_prefix='auto'
network.@switch[0]=switch
network.@switch[0].name='switch0'
network.@switch[0].reset='1'
network.@switch[0].enable_vlan='1'
network.@switch_vlan[0]=switch_vlan
network.@switch_vlan[0].device='switch0'
network.@switch_vlan[0].vlan='1'
network.@switch_vlan[0].ports='0 6t'
network.@switch_vlan[1]=switch_vlan
network.@switch_vlan[1].device='switch0'
network.@switch_vlan[1].vlan='2'
network.@switch_vlan[1].ports='1 2 6t'
network.@device[0]=device
network.@device[0].name='br-lan'
network.@device[0].type='bridge'
network.@device[0].ports='eth0.2'
network.lan=interface
network.lan.device='br-lan'
network.lan.proto='static'
network.lan.ipaddr='192.168.56.1'
network.lan.netmask='255.255.255.0'
network.wan=interface
network.wan.device='eth0.1'
network.wan.proto='dhcp'
root@openwrt:/#



###开启WIFI

root@openwrt:/# uci show wireless
wireless.radio0=wifi-device
wireless.radio0.type='mac80211'
wireless.radio0.path='platform/10300000.wmac'
wireless.radio0.channel='1'
wireless.radio0.band='2g'
wireless.radio0.htmode='HT20'
wireless.radio0.disabled='1'
wireless.default_radio0=wifi-iface
wireless.default_radio0.device='radio0'
wireless.default_radio0.network='lan'
wireless.default_radio0.mode='ap'
wireless.default_radio0.ssid='OpenWrt'
wireless.default_radio0.encryption='none'


###设置ap的ssid

uci set wireless.default_radio0.ssid=openwrt_ap_test

###设置密码的加密方法
uci set wireless.default_radio0.encryption=psk2

###设置密码
uci set wireless.default_radio0.key=test123456
###开启WiFi
uci set wireless.radio0.disabled=0






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值