[OpenWrt-Devel] How am I supposed to change settings in /etc/config/network of default root file system of OpenWRT?

Magnus Kroken mkroken at gmail.com
Tue May 19 05:37:58 EDT 2020


On 19.05.2020 08:30, Jeonghum Joh wrote:
 > config interface 'wwan'
>          option ifname 'usb0'
>          option proto 'dhcp'
> So I added something like below to 
> package/base-files/files/etc/board.d/99-default_network :
>    ucidef_set_interface_lan 'eth0'
>    [ -d /sys/class/net/eth1 ] && ucidef_set_interface_wan 'eth1'
> +[ -d /sys/class/net/usb0 ] && ucidef_set_interface_wan 'usb0'
> But this didn't resolve my problem.
> I think I can just make some commands into startup script.
> Isn't there more grace approach for me to automatically add usb0 
> interface into /etc/config/network?

As already suggested, use the files/ directory to include files.

$ cd openwrt # change to the root of your OpenWrt build environment
$ mkdir -p files/etc/uci-defaults
$ mkdir -p files/etc/config

Now you have two options.

1. Put your complete working /etc/config/network file in the files/ 
tree, so it resides at files/etc/config/network.

2. Write a script with the UCI commands needed to change your config, 
and put it in files/etc/uci-defaults. I name mine e.g. 
zzz_33_device_config, so that they are executed as late as possible.

The commands you would need for option 2 is probably:

uci -q set network.wwan=interface
uci -q set network.wwan.proto='dhcp'
uci -q set network.wwan.ifname='usb0'
exit 0

This is very simple, you may want to script checks to ensure the script 
is running on correct device (e.g. by checking for a MAC address), and 
if the usb0 device exists.

Magnus Kroken

> Thank you in advance.
> Jeonghum

openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list