ESPHome DHCP Server Question

Hi everyone.

I have 3 sonoff on/off plugs which are flashed with ESPHome (version 2024.3.0). Lately, on my Unifi networking devices (UDM Pro) I’ve been having issues with a non-managed IP space getting handled out (192.168.4.x). I’ve worked with unifi support and they said they have narrowed it down to 3 specific devices which are roque DHCP servers, which happen to be the 3 sonoff on/off devices running ESP home.

Does ESPHome run a dhcp server? I could see it if it was in AP mode, but not when it’s connected to an existing wireless network. Anyone run into this issue?

Thank you

So, I went digging around the actual code (ESPHome: esphome::wifi::WiFiAP Class Reference) and I cannot find anything relating to any embedded DHCP server. Not that there isn’t one somewhere in the code, I just didn’t find it in my search.

Personally what I would do is give those 3 sonoff devices static IPs in some lower or upper range of your subnet and then change your DHCP address pool to be above/below those addresses. The other thing you can probably do is setup a firewall rule blocking UDP ports 67/68 to those three addresses. That should prevent them from trying to hand out IP addresses. I have quite a few of them running and they have never affected my DHCP pool on my UDM Pro. But, I also use 192.168.107.0 for all my IOT stuff so it doesn’t conflict with the 192.168.4.0 subnet.

The scorched earth approach to to move your 192.168.4.0 subnet to some other private address. :wink: lol

With respect, the AP must hand out IP addresses. So surely it must include a DHCP server.

but it should only be on when in ap mode.

1 Like

100% correct. I just couldn’t find any mention of a DHCP server in the code itself is all I was saying.

Understood.

By the way, for OP’s benefit, you can check where DHCP is running via nmap

nmap -sU 192.168.20.241 -p67-68

Where the ip address is the one you want to test.

My theory?

The sonoff devices are falling off the lan and starting AP mode, and offering DHCP addresses, as they are designed to do.

2 Likes

Agreed, but that’s only in AP mode. how would they hand out IP’s on a network they aren’t attached too. Its honestly what I was thinking also, but I don’t see how. Could they bridge, eg: be part of both networks? For now, I’ve just removed the devices from the network.

Make a test. Power off all x3 Sonoff devices and check it out.

Have 30+ ESPHome (mostly Sonoff) in network, with 2023.12 version.
No troubles with rogue DHCP servers. But who knows reg. 2024.03…

A DHCP server listens for devices requesting DHCPDISCOVERY packets, which a DHCP client broadcasts to 255.255.255.255.

1 Like

Did you set the fallback AP on the ESPHome to the same as your normal network?

all 3 are disconnected completely. Monitoring the network to see if the problem happens.