Enable / Disable DHCP via Script

Hey Guys -

I'm looking to see what the best method is to enable / disable DHCP on my router via script. Long story, short; I'm planning to use a domain controller for the primary DHCP server. If it's not available, I would like my router's DHCP to start. Once the DC's back up, I want the router's DHCP off again.

My thought was to have a process running in the background that pings the DC every few seconds and would enable DHCP on the router if the DC goes down and disable it once back up.

My router is a Linksys WRT1900ACS running LEDE SNAPSHOT r9028-75fdf3ba01 Kernel 4.14.91. I do have SSH enabled and assume the script would involve it. The monitoring and script will be run from a Windows 10 system.

Any suggestions or alternate methods? Thanks!

Personally, I'd suggest command-bound SSH keys, one for "DHCP on" and the other for "DHCP off", if you're going to be doing this remotely and automatically.

Is there a reason not to run the monitor on the OpenWrt box? I would hope that there was a reasonable way to tell without authentication to the DC if the DC us up or not. ping just says its interface is up, not if it is actually running DHCP.

How is the DHCP server and the DC going to communicate, so each one honours the IP addresses issued by the other one...?


Sorry for late reply - been covered up!

I honestly didn't consider them communicating nor exchanging leases. I guess the best bet would be to throw together an old PC or make space on ESXi so I can have a DC that stays onsite 24/7 which I could join to the same domain, promote as a DC, then remove laptop VM one.

Anyways - after thinking about what you brought up, if I do build it and plan for it to be the dedicated DHCP server; is there anything beyond disabling DHCP in LEDE/OpenWRT you suggest need to be configured on the router?


Disabling DHCP on the OpenWrt instance should be sufficient. If you're using "off-board" DNS, then you could disable that as well. I believe that if you're neither running DHCP nor DNS, then you could disable dnsmasq completely.