How does DHCP allocate leases on OpenWrt?

Normally routers allow specifying DHCP pool.
On OpenWrt, there is no such user specified pool.

I have found settings under DHCP / Advanced Settings:
Allocate IPs sequentially.
Max DHCP Leases.

My problem is that I like to specify static IPs for infrastructure (servers, switches). I do have a list of statically allocated IPs on my LAN.
Most static IPs are low numbers, couple are higher, like 198, 199.

I have noticed that under Routing... IP4 Neighbours Tab gives a comprehensive list of IPs active on the LAN.

Does OpenWrt DHCP avoid leasing any IPs visible on the IP4 Neighbours list?.... those which are NOT already listed on the dhcp.leases file?

PS so far I've had no clashes betw static & DHCP, but OpenWrt has come close once or twice, hence the question.

This is disabled by default. When enabled, it does what it says, but this means that devices will likely not maintain the same IP address. However, when this is disabled, Dnsmasq will use a hash of the client's MAC address to select the IP address provided in the lease.

Generally, this is not used -- your interface's DHCP server has start and limit (size of the pool) parameters for this purpose.

Are these static IPs, or DHCP reservations (i.e. a statically assigned address via DHCP)?

TBH, I'm not sure. However, the guidance is always to assign static IP addresses only outside the DHCP pool. Even if those addresses are avoided, the danger is that the neighbors list may not be up to date if a device didn't respond or is powered off/disconnected or any number of other situations that may cause the list to be incomplete.

One way around this, though, is to set a DHCP reservation specifically for the devices that have static addresses so that the DHCP server will never try to allocate the address to another device.

What do you mean it "has come close"? The only way one could evaluate "close" is if you're using sequential IP allocation or if your DHCP pool was nearing exhaustion.

1 Like

You sure?

# from /etc/config/dhcp 

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv4 'server'

Mine does.

192.168.1.100 - 192.168.1.149

So by default, you can use for static addressing:

  • 192.168.1.2 - 192.168.1.99

and

  • 192.168.1.150 - 192.168.1.254
1 Like

Well, just looking at the LuCi interface, most of which is very well documented, there was no indication of the existence is /etc/config/dhcp

This is what I was looking for.
I'll just edit my /config/dhcp.... tnx.

Yeah, I can just use a small DHCP pool.... 50-100, then anything before 50 & after 100 is left for static (hard coded, not via router). I really don't need many DHCP anyway.... Or many static either.... Just don't want to mix them!

I do my static hard coded bc I like to actually choose the IP allocated to a particular device.... rather than taking any DHCP lease & "locking" the lease IP.

Appreciate the pointer to the config/dhcp... found mine ofc.

I could have looked at /etc/config.... didn't think to.... I looked at LuCi instead.
I should get used to looking at the /etc/config folder I guess....!

In LuCI, the DHCP server is found under

Network > Interfaces > [edit network of interest] > DHCP server

Note that the limit parameter is the size of the pool, not the last value.

The range of the pool is:

start -to- (start + limit - 1)
3 Likes

Thanks, found the LuCI interface.

Would not have found that on my own, although in a way, its obv, since different interfaces = different networks = each network (subnet) having its own IP pool.

1 Like

In LuCI you would browse to:

Network > Interfaces > LAN > Edit > DHCP Server

(I see psherman already mentioned it.)

2 Likes