OpenWrt Forum Archive

Topic: Fixed IP

The content of this topic has been archived on 30 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi guys,

I'm trying to set static ip's in my image build without having to do it through the menuconfig system.

I have a package that provides /etc/config/network , but it seems that I *have* to set the ip through the menuconfig (which I don't want to do, as my plan is for different packages to have different IP's.)

How do I go about getting this right?


Use uci-defaults. Put a UCI batch in your build-system at files/etc/uci-defaults/defaults, make it executable and rebuild the image. Don't forget to make the script executable (chmod a+x files/etc/uci-defaults/defaults).

Example uci-defaults scriptn (files/etc/uci-defaults/defaults):


uci batch <<-EOF
    # Set the default LuCI WebUI theme to openwrt-light
    set luci.main.mediaurlbase=/luci-static/openwrt-light
    commit luci

    # Set the correct timezone for Europe/Berlin
    set system.@system[0].timezone=MEST-2
    commit system

    # Change the default NTP servers to some local ones
    set ntpclient.@ntpserver[0]
    set ntpclient.@ntpserver[1]
    set ntpclient.@ntpserver[2]
    set ntpclient.@ntpserver[3]
    commit ntpclient

    # Set a static leases
    add luci_ethers static_lease
    set luci_ethers.@static_lease[-1].macaddr='00:0c:29:f0:a5:5e'
    set luci_ethers.@static_lease[-1].ipaddr=''
    commit luci_ethers

    # Set a different IP address for LAN
    set network.lan.ipaddr=
    commit network

With some scripting this should work. The uci-defaults scripts will run once on the first boot after flashing.

(Last edited by Yanira on 20 Oct 2008, 12:48)

Thanks alot.  Makes sense, I'll  do it this way. smile


The discussion might have continued from here.