WiFi.hostByName returns outdated IP

I am using the WiFi.hostByName function to obtain the IP for a given hostname on ESP32 and ESP8266 systems.

The host is a Raspberry Pi which for a long time had a static address. I now wanted to change this into a dynamic IP obtained from DHCP. The new IP is valid and shown in my router web interface, I also can ping it. My ESP32/9266 sketches however still return the old IP with WiFi.hostByName, even after a reboot of the router/dhcp server and ESP systems.

In a description of the underlying dns_gethostbyname() I found that this function immediately returns „ERR_OK if hostname is a valid IP address string or the host name is already in the local names table.“

What can I do in order to get the new IP?

Any hint is welcome.


What can I do in order to get the new IP?

Take care that the DNS gets the IP update. If you request the same function on your PC, what do you get? Most probably the same old IP as your DNS doesn't know about the change yet.

Thanks for the reply.

I shutdown the Raspi and deleted it from the list of known devices. After reboot I got the new dynamic IP.