Disable DHCP on OpenWrt through CLI?

Ahoy friends.
I'm almost done with my VRRP setup, and in a few days i'll be ready to share my experience on the wiki.
Unfortunately there is still one single issue.
Is there a way to disable DHCP on a device through the CLI?

I want to execute it through a notify_master and notify_backup script.
It's being executed, but i can't see any change in the DHCP behaviour.
Is there something i'm missing?

Thanks in advance!

notify_backup:

#!/bin/sh

logger "Running BACKUP Script.."
uci set dhcp.lan.ignore="1"
uci commit dhcp
/etc/init.d/dnsmasq stop
/etc/init.d/odhcpd stop

Looks right to me if with "disable DHCP" you mean "stop provding DHCP leases".

Exactly! Unfortunately my script is not achieving this goal.

Try putting the following in /etc/rc.local to prevent updates from re-adding the DHCP services.

for i in dnsmasq odhcpd; do
  if /etc/init.d/"$i" enabled; then
    /etc/init.d/"$i" disable
    /etc/init.d/"$i" stop
  fi
done

The script will disable handing out dhcpv4 and stop odhcpd. If the router restarts RA and dhcpv6 will start working again. Also it will stop nameserver from working, not sure if you want that.
What is not working exactly?

What i want to achieve with my script, is to only disable the distribution of DHCP leases, DNS should keep running.
Unfortunately dnsmasq keeps handing out DHCP leases.

uci set dhcp.lan.ignore='1'
uci commit dhcp
/etc/init.d/dnsmasq restart

This will work and not cause collateral damage.

1 Like

How did you troubleshoot?
If you run the script by yourself does it work?
If you call it from another application, does it actually run?

2 Likes

Another thing to realize is that disabling the DHCP server does not revoke existing DHCP leases. It simply stops the server from allocating new leases. Therefore, the clients that already have leases will continue to use their assigned IP addresses until the lease expires. By default, the lease time is 12 hours. You can obviously force the issue by releasing/renewing the leases on the client machines.

4 Likes

Good point by @psherman . You can't expect to release the already allocated addresses when you stop dhcpd.

1 Like

When a client tries to renew, it'll offer its ciaddr (current address). The server can extend the lease or refuse to renew that lease and offer a new one. In both cases the server assignment table should be updated.

https://datatracker.ietf.org/doc/html/rfc2131#section-4.3.2

By default clients will start trying to renew leases with the original server at T1 (0.5 * duration_of_lease). At T2 (0.875 * duration_of_lease) it will start sending broadcasts.

You could have the servers offer different ranges. One could do 192.168.10.100-149, the other can do 192.168.10.150-199, etc.