[OpenWrt-Devel] How to pre-define the LAN IP

Magnus Kroken mkroken at gmail.com
Wed Feb 28 10:47:26 EST 2018

Hi Bill

On 28.02.2018 15:18, Bill Yuan wrote:
> Hi,
> I noticed the default LAN IP is still even after I 
> configured the "preinit network interface" in "preinit configuration 
> options". Can someone please share with me where is the proper way to 
> pre-define the LAN IP?

The build system does not include a way to do this. You can do this by 
including additional files in your image. To do this, create a directory 
"files" in the root of the build directory (same directory you run make 
menuconfig from).

You can either include a full network configuration file in the image, 
or you can include a script that will execute after the device has 
booted, which configures the IP address.

For a full configuration, configure the network as you want it to be, 
then copy /etc/config/network from your OpenWrt device to your files/ 
folder, so it ends up as: files/etc/config/network.

For a script, here is a snippet of how I do this on my devices. You can 
omit the if check, I do this so I can use the same script on several 


if [ "$(ip link show eth0 | awk '/ether/ {print $2}')" == 
"11:22:33:44:55:66" -a "$(uci -q get network.lan.ipaddr)" == "" ]
         uci -q set network.lan.ipaddr=''

/etc/init.d/network restart

Put this in files/etc/uci-defaults/zz_changeip4.sh. The zz prefix 
ensures the file is executed last in the uci-defaults folder, if it 
executes too early the base network config may not be in place yet.

> Regards,
> bycn82

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

More information about the openwrt-devel mailing list