OpenWrt Forum Archive

Topic: how to change default 192.168.1.1 in build settings

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

Hi, I need to upgrade router from stock to openwrt and because I'm doing this remotely, I need to do it right to save a long trip. Router is connected to the network via lan port, so I just need to preset different ip (and disable dhcp, which I can do in package/network/services/dnsmasq/files/dhcp.conf). Default openwrt IP 192.168.1.1 would make IP conflict after fw update.

I found file ./package/base-files/files/bin/config_generate which looks promising, closely this section:

        case "$protocol" in
                static)
                        local ipad
                        case "$1" in
                                lan) ipad=${ipaddr:-"192.168.1.1"} ;;
                                *) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
                        esac

                        netm=${netmask:-"255.255.255.0"}

                        uci -q batch <<-EOF
                                set network.$1.proto='static'
                                set network.$1.ipaddr='$ipad'
                                set network.$1.netmask='$netm'
                                set network.$1.ip6assign='60'
                        EOF
                ;;

But I never did this before. Can I just replace 192.168.1.1 with something like 192.168.1.111 and opewnrt will boot with this IP by default (also after firstboot)? Or is there another "documented" way of doing this?

Thanks.

Another question: everytime I modify some file like this, do I have to make clean, or make will know it's newer and compile it again?

(Last edited by nozombian on 10 Feb 2018, 17:01)

That should be the right place for most routers. (a few exotic targets ship a network config differently).

But if you want the same address to be also in the failsafe mode (using "preinit" settings), you need to set that in the menuconfig:
https://git.openwrt.org/?p=openwrt/open … b=HEAD#l76
(or you could change that preinit ip in base-files Makefile, where there is a similar fallback default for that item)

But I think that the easiest thing would be to ship your own /etc/config/network as a custom file included in the firmware. You could tinker all options in it as you want and then just included it in the image. A new /etc/config/network is only generated if it is missing when the router boots for the first time. If there is your own file, it is used.
https://lede-project.org/docs/guide-dev … stom_files
Similar approach works also with imagebuilder.

Great, thank you. And do I have to make clean in case I made another change? Or make will notice changed files?

You need to at least recompile base-files.

Make will not notice this kind of changes for most packages,  but I think that basefiles is a bit special and always gets made in a normal firmware make. So changes to are likely picked up in any case.

But I do typically a make clean before compiling the final image for burning. It is always the safe approach.

(Last edited by hnyman on 10 Feb 2018, 17:59)

Ok, thank you. I used to make clean with old versions of openwrt frequently, but I don't recall I had problem with unclean build on recent ledes/openwrts so I don't make clean often for some time, because after it takes more than hour to compile on my build system :-(

So I edited ./package/base-files/files/bin/config_generate and remote upgrade worked like a charm, thanks for help again. After make clean compilation took only about 25 minutes, so not the whole hour, it's good ;-)

The discussion might have continued from here.