Issue changing between DHCP client and static IP on boot

I wasn't aware of that - that's useful.

To overcome that, would it be a case of just checking the upstream routers subnet and changing it on the downstream router if required? I assume this could be done via a script.

1 Like

With all due respect, may I suggest reading the documentation?

From the main page at

Security: OpenWrt's standard installation is secure by default, with Wi-Fi disabled,

1 Like

I assume this is done all over the world in various of ways everyday - it's required in networking for a router to know it should forward the packet across interfaces. You just have to pick a different /24 subnet. perhaps.

(You would number the router as 2.1)

1 Like

Yes, you could do it by a script, or you could just check it the once, and set it manually. Unless you reset back to factory defaults, the address is unlikely to revert on its own.

1 Like

Yeah the issue is it won't always be the same upstream router being connected to - so will put a script together to check and change accordingly.

Thanks for your assistance @lleachii and @iplaywithtoys

1 Like

That's going to be tricky. If you know that the upstream router always issues addresses by DHCP, then you can whip up a very simple "does WAN subnet match (or overlap, in the event of a different mask) the LAN subnet?" test, and then edit the LAN address accordingly.

But if you use an upstream router which requires clients to have static addresses, then I'm not sure what the best approach for scripting a mix of DHCP and static scenarios might be.

1 Like

@iplaywithtoys are you aware of a way to retrieve the upstream routers subnet to check against? The upstream router is not using OpenWrt

If the upstream router is a DHCP server, then all you need do is check the IP address details of OpenWRT's WAN interface; that'll tell you what you need to know.

1 Like

Hi @iplaywithtoys ,

I was wondering if you could just check over my configuration to make sure I'm not doing something obviously wrong. Output of /etc/config/network below -

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr ''
        option netmask ''

config globals 'globals'
        option ula_prefix 'fdcb:ae54:84eb::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0.1'

config interface 'lan'
        option proto 'static'
        option ipaddr ''
        option netmask ''
        option ip6assign '60'
        list dns ''
        option gateway ''
        option device 'br-lan'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option ports '4 6t'

config interface 'wan'
        option proto 'dhcp'
        option device 'eth0'

The output of uci show network.wan is


When this is connected to an upstream router and I use

wan_subnet=$(uci get network.wan.ipaddr)

I get uci: Entry not found. the network.lan.ipaddr is found fine.

Why do you continue to have an upstream gateway defined for the LAN interface?

That won't work for DHCP configurations. uci get reads configuration files.

Instead, you would need to find the current IP address and netmask issued to the WAN interface.

This thread - Redirect LAN ip to WAN gateway ip - #15 by iplaywithtoys - contains some suggestions about how to do so.

Thanks - i'll take a look.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.