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?

Thanks!

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):

#!/bin/sh

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].hostname=ptbtime1.ptb.de
    set ntpclient.@ntpserver[1].hostname=ptbtime2.ptb.de
    set ntpclient.@ntpserver[2].hostname=de.pool.ntp.org
    set ntpclient.@ntpserver[3].hostname=europe.pool.ntp.org
    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='192.168.1.222'
    commit luci_ethers

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

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, 10:48)

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

Cheers,
Pieter

The discussion might have continued from here.