[GH-ISSUE #1544] dns does not look to be set properly after connecting to wifi #1318

Open
opened 2026-02-28 01:29:34 +03:00 by kerem · 9 comments
Owner

Originally created by @BouchardClaude on GitHub (Jan 8, 2023).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1544

Basic Infos

I appear that the dns is not set properly when using DHCP STA , preventing to communicate with services using dns name.

Description

When using autoconnect, the ip, mask and gateway are set properly, but it look like the dns is never set. I'm not sure if its a desired behaviour or if its linked to WifiManager itself or a sub library.

Additional libraries:

Sketch

Exemple of code that produce the ouput

   if (wm.autoConnect(hostname, pass)) {
        debugPrintf("WiFi connected - IP = %i.%i.%i.%i\n", WiFi.localIP()[0],
                    WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]);
        uint8_t dns_no;
        WiFi.dnsIP(dns_no);
        debugPrintf("DNS-ADDRESS: %d\n", dns_no);

will output the following:

Debug Messages

*wm:[2] Connection result: WL_CONNECTED
*wm:[1] AutoConnect: SUCCESS
*wm:[2] Connected in 4519 ms
*wm:[1] STA IP Address: 192.168.5.43
[00:00:04] WiFi connected - IP = 192.168.5.43
[00:00:04] DNS-ADDRESS: 0

And ill be able to use anything not using DNS.
Is theyre a way to hard-set the DNS without using static ip?

Originally created by @BouchardClaude on GitHub (Jan 8, 2023). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1544 ### Basic Infos I appear that the dns is not set properly when using DHCP STA , preventing to communicate with services using dns name. ### Description When using autoconnect, the ip, mask and gateway are set properly, but it look like the dns is never set. I'm not sure if its a desired behaviour or if its linked to WifiManager itself or a sub library. Additional libraries: ### Sketch Exemple of code that produce the ouput ``` if (wm.autoConnect(hostname, pass)) { debugPrintf("WiFi connected - IP = %i.%i.%i.%i\n", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]); uint8_t dns_no; WiFi.dnsIP(dns_no); debugPrintf("DNS-ADDRESS: %d\n", dns_no); ``` will output the following: ### Debug Messages ``` *wm:[2] Connection result: WL_CONNECTED *wm:[1] AutoConnect: SUCCESS *wm:[2] Connected in 4519 ms *wm:[1] STA IP Address: 192.168.5.43 [00:00:04] WiFi connected - IP = 192.168.5.43 [00:00:04] DNS-ADDRESS: 0 ``` And ill be able to use anything not using DNS. Is theyre a way to hard-set the DNS without using static ip?
Author
Owner

@EtoTen commented on GitHub (Jan 13, 2023):

Try

Serial.println( "DNS:" + WiFi.dnsIP().toString());`

also try

WiFi.config(WiFi.localIP(),` WiFi.gatewayIP(), WiFi.subnetMask(), IPAddress(8,8,8,8)); 

( from https://github.com/espressif/arduino-esp32/issues/2990 )

<!-- gh-comment-id:1381165086 --> @EtoTen commented on GitHub (Jan 13, 2023): Try ```cpp Serial.println( "DNS:" + WiFi.dnsIP().toString());` ``` also try ```cpp WiFi.config(WiFi.localIP(),` WiFi.gatewayIP(), WiFi.subnetMask(), IPAddress(8,8,8,8)); ``` ( from https://github.com/espressif/arduino-esp32/issues/2990 )
Author
Owner

@tablatronix commented on GitHub (Jan 13, 2023):

What esp lib version?

And what is your DNS supposed to be ?

<!-- gh-comment-id:1381172396 --> @tablatronix commented on GitHub (Jan 13, 2023): What esp lib version? And what is your DNS supposed to be ?
Author
Owner

@tablatronix commented on GitHub (Jan 13, 2023):

Works for me


[INFORMATION] TEST
*wm:[SYS] WM version:  v2.0.15-rc.1
*wm:[SYS] Arduino version:  2.0.6
*wm:[SYS] ESP SDK version:  v4.4.3
*wm:[SYS] Free heap:        288364
*wm:[SYS] Chip ID: 3753011116
*wm:[SYS] Chip Model: ESP32-D0WDQ5
*wm:[SYS] Chip Cores: 2
*wm:[SYS] Chip Rev: 1

....
connected...yeey :)
[WIFI] WIFI INFO DEBUG
[WIFI] SAVED: YES
[WIFI] SSID:xxxxxx
[WIFI] PASS:xxxxxx
[WIFI] HOSTNAME: WM_ESP32_DFB267AC
[WIFI] DNS:192.168.20.190
[WIFI] DNS:192.168.20.1
<!-- gh-comment-id:1381243358 --> @tablatronix commented on GitHub (Jan 13, 2023): Works for me ```php [INFORMATION] TEST *wm:[SYS] WM version: v2.0.15-rc.1 *wm:[SYS] Arduino version: 2.0.6 *wm:[SYS] ESP SDK version: v4.4.3 *wm:[SYS] Free heap: 288364 *wm:[SYS] Chip ID: 3753011116 *wm:[SYS] Chip Model: ESP32-D0WDQ5 *wm:[SYS] Chip Cores: 2 *wm:[SYS] Chip Rev: 1 .... connected...yeey :) [WIFI] WIFI INFO DEBUG [WIFI] SAVED: YES [WIFI] SSID:xxxxxx [WIFI] PASS:xxxxxx [WIFI] HOSTNAME: WM_ESP32_DFB267AC [WIFI] DNS:192.168.20.190 [WIFI] DNS:192.168.20.1 ```
Author
Owner

@BouchardClaude commented on GitHub (Jan 13, 2023):

Thanks for the help :)

Okay so first I completly misunderstood the dnsIP() usage in c++. @EtoTen thanks to your snippet i was able to confirm that I'm receiving the DNS ip correcly.

To test it, I try to sync the time.

debugPrintf("DNS - IP = %i.%i.%i.%i\n", WiFi.dnsIP()[0],WiFi.dnsIP()[1], WiFi.dnsIP()[2], WiFi.dnsIP()[3]);
debugPrintf("GW - IP = %i.%i.%i.%i\n", WiFi.gatewayIP()[0],WiFi.gatewayIP()[1], WiFi.gatewayIP()[2], WiFi.gatewayIP()[3]);
debugPrintf("GW - IP = %i.%i.%i.%i\n", WiFi.subnetMask()[0], WiFi.subnetMask()[1], WiFi.subnetMask()[2], WiFi.subnetMask()[3]);

 timeSync("GMT-5", "time-a-g.nist.gov", "utcnist2.colorado.edu");

and it gave me this ( everything look look ip wise, but it fail to set the time ( or to do any dns query that I tested)

[00:00:05] WiFi connected - IP = 192.168.5.35
[00:00:05] MAC-ADDRESS: 3616196xxxxx
[00:00:05] DNS - IP = 192.168.4.1
[00:00:05] GW - IP = 192.168.4.1
[00:00:05] GW - IP = 255.255.252.0
Syncing time........................................
Synchronized time: Thu Jan  1 05:00:25 1970  ( time failed to sync)

but if I dont use dns, then its working ( so packets are going in and out and are forwareded properly by the router.
example: using timeSync("GMT-5", "129.6.15.28v", "128.138.141.172");

[00:00:05] MAC-ADDRESS: 3616196358217
[00:00:05] DNS - IP = 192.168.4.1
[00:00:05] GW - IP = 192.168.4.1
[00:00:05] GW - IP = 255.255.252.0
Syncing time.
Synchronized time: Fri Jan 13 18:09:35 2023````( time is good)

The funny thing is I tried with a different network and it worked just fine ( exemple using my cell as wifi AP and using dns to sync time)

timeSync("GMT-5", "time-a-g.nist.gov", "utcnist2.colorado.edu");
will work perfetly:

[00:01:19] WiFi connected - IP = 192.168.54.171
[00:01:19] MAC-ADDRESS: 3616196358xxx
[00:01:19] DNS - IP = 192.168.54.123
[00:01:19] GW - IP = 192.168.54.123
[00:01:19] GW - IP = 255.255.255.0
Syncing time...............................
Synchronized time: Fri Jan 13 19:17:30 2023

Can it be that the issue is with the subnet I use internally confliting with the one used when in portal mode?
I cannot exclude something fishy with the router too, but every device I have use this with no issue.

<!-- gh-comment-id:1381928619 --> @BouchardClaude commented on GitHub (Jan 13, 2023): Thanks for the help :) Okay so first I completly misunderstood the dnsIP() usage in c++. @EtoTen thanks to your snippet i was able to confirm that I'm receiving the DNS ip correcly. To test it, I try to sync the time. ``` debugPrintf("DNS - IP = %i.%i.%i.%i\n", WiFi.dnsIP()[0],WiFi.dnsIP()[1], WiFi.dnsIP()[2], WiFi.dnsIP()[3]); debugPrintf("GW - IP = %i.%i.%i.%i\n", WiFi.gatewayIP()[0],WiFi.gatewayIP()[1], WiFi.gatewayIP()[2], WiFi.gatewayIP()[3]); debugPrintf("GW - IP = %i.%i.%i.%i\n", WiFi.subnetMask()[0], WiFi.subnetMask()[1], WiFi.subnetMask()[2], WiFi.subnetMask()[3]); timeSync("GMT-5", "time-a-g.nist.gov", "utcnist2.colorado.edu"); ```` and it gave me this ( everything look look ip wise, but it fail to set the time ( or to do any dns query that I tested) ``` [00:00:05] WiFi connected - IP = 192.168.5.35 [00:00:05] MAC-ADDRESS: 3616196xxxxx [00:00:05] DNS - IP = 192.168.4.1 [00:00:05] GW - IP = 192.168.4.1 [00:00:05] GW - IP = 255.255.252.0 Syncing time........................................ Synchronized time: Thu Jan 1 05:00:25 1970 ( time failed to sync) ``` but if I dont use dns, then its working ( so packets are going in and out and are forwareded properly by the router. example: using timeSync("GMT-5", "129.6.15.28v", "128.138.141.172"); ```[00:00:05] WiFi connected - IP = 192.168.5.35 [00:00:05] MAC-ADDRESS: 3616196358217 [00:00:05] DNS - IP = 192.168.4.1 [00:00:05] GW - IP = 192.168.4.1 [00:00:05] GW - IP = 255.255.252.0 Syncing time. Synchronized time: Fri Jan 13 18:09:35 2023````( time is good) ```` The funny thing is I tried with a different network and it worked just fine ( exemple using my cell as wifi AP and using dns to sync time) ` timeSync("GMT-5", "time-a-g.nist.gov", "utcnist2.colorado.edu"); ` will work perfetly: ``` [00:01:19] WiFi connected - IP = 192.168.54.171 [00:01:19] MAC-ADDRESS: 3616196358xxx [00:01:19] DNS - IP = 192.168.54.123 [00:01:19] GW - IP = 192.168.54.123 [00:01:19] GW - IP = 255.255.255.0 Syncing time............................... Synchronized time: Fri Jan 13 19:17:30 2023 ``` Can it be that the issue is with the subnet I use internally confliting with the one used when in portal mode? I cannot exclude something fishy with the router too, but every device I have use this with no issue.
Author
Owner

@tablatronix commented on GitHub (Jan 13, 2023):

Yeah or it could be subnet mask not allowing that ip, not sure. also just use .toString() for printing ips.

<!-- gh-comment-id:1382419709 --> @tablatronix commented on GitHub (Jan 13, 2023): Yeah or it could be subnet mask not allowing that ip, not sure. also just use .toString() for printing ips.
Author
Owner

@BouchardClaude commented on GitHub (Jan 13, 2023):

thats why im suspecting a bug, cause 192.168.4.1 255.255.252.0 is a valid subnet and 192.168.5.35 is a valid ip in this subnet
If I take the same (non working ) router setup and change the mask of the network to be a /24 then everything is working good
[22:27:41] WiFi connected - IP = 192.168.0.26
[22:27:41] MAC-ADDRESS: 3616196358xxx
[22:27:41] DNS - IP = 192.168.0.1
[22:27:41] GW - IP = 192.168.0.1
[22:27:41] GW - IP = 255.255.255.0
Syncing time
Synchronized time: Sat Jan 14 03:27:41 2023

So I think the network mask is unproperly process OR the 192.168.4.x range is conflicting with something, but thats unlikely since at that point its in STA mode

<!-- gh-comment-id:1382468521 --> @BouchardClaude commented on GitHub (Jan 13, 2023): thats why im suspecting a bug, cause 192.168.4.1 255.255.252.0 is a valid subnet and 192.168.5.35 is a valid ip in this subnet If I take the same (non working ) router setup and change the mask of the network to be a /24 then everything is working good [22:27:41] WiFi connected - IP = 192.168.0.26 [22:27:41] MAC-ADDRESS: 3616196358xxx [22:27:41] DNS - IP = 192.168.0.1 [22:27:41] GW - IP = 192.168.0.1 [22:27:41] GW - IP = 255.255.255.0 Syncing time Synchronized time: Sat Jan 14 03:27:41 2023 So I think the network mask is unproperly process OR the 192.168.4.x range is conflicting with something, but thats unlikely since at that point its in STA mode
Author
Owner

@tablatronix commented on GitHub (Jan 14, 2023):

There is a way to change the default server ip but I forget at the moment how. Would be interesting to test a different class. Ill try to test this in my lab one day.

<!-- gh-comment-id:1382644237 --> @tablatronix commented on GitHub (Jan 14, 2023): There is a way to change the default server ip but I forget at the moment how. Would be interesting to test a different class. Ill try to test this in my lab one day.
Author
Owner

@patrickvorgers commented on GitHub (Jan 15, 2023):

It seems to me that I have the same problem. I added the WiFiManager to one of my programs and without it my MQTT broker (mqttbroker) is resolved normally but with WiFiManager I can only use the IP-number directy.

17:45:20.990 -> *WM: 192.168.0.131
17:45:20.990 -> DNS: 192.168.0.200
17:45:20.990 -> GW: 192.168.0.200
17:45:20.990 -> GW subnet mask: 255.255.255.0

The strange thing is that when I look in my Mikrotik router that the DNS request (wireShark) for both the working and failing programs look exactly the same. For one request the Mikrotik router returns the IP and for the other it doesn't.

<!-- gh-comment-id:1383198151 --> @patrickvorgers commented on GitHub (Jan 15, 2023): It seems to me that I have the same problem. I added the WiFiManager to one of my programs and without it my MQTT broker (mqttbroker) is resolved normally but with WiFiManager I can only use the IP-number directy. 17:45:20.990 -> *WM: 192.168.0.131 17:45:20.990 -> DNS: 192.168.0.200 17:45:20.990 -> GW: 192.168.0.200 17:45:20.990 -> GW subnet mask: 255.255.255.0 The strange thing is that when I look in my Mikrotik router that the DNS request (wireShark) for both the working and failing programs look exactly the same. For one request the Mikrotik router returns the IP and for the other it doesn't.
Author
Owner

@BouchardClaude commented on GitHub (Jan 16, 2023):

That's interesting cause its the exact same issue for me (MQTT broker) , but your mask is /24 so I was probably wrong thinking its related to mask.
Funny part is I tried many time, and sometimes it work, sometimes no with the same setup .. so so far its not easy to point a finger on whats not working. I'm working on trying to be able to reproduce the issue every time so we can see what element is causing the issue

<!-- gh-comment-id:1384142035 --> @BouchardClaude commented on GitHub (Jan 16, 2023): That's interesting cause its the exact same issue for me (MQTT broker) , but your mask is /24 so I was probably wrong thinking its related to mask. Funny part is I tried many time, and sometimes it work, sometimes no with the same setup .. so so far its not easy to point a finger on whats not working. I'm working on trying to be able to reproduce the issue every time so we can see what element is causing the issue
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1318
No description provided.