Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS lookup problem #8780

Open
brunoudi opened this issue Dec 31, 2022 · 8 comments
Open

DNS lookup problem #8780

brunoudi opened this issue Dec 31, 2022 · 8 comments
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@brunoudi
Copy link

brunoudi commented Dec 31, 2022

Basic Infos

  • [ x ] This issue complies with the issue POLICY doc.
  • [ x ] I have read the documentation at readthedocs and the issue is not addressed there.
  • [ x ] I have tested that the issue is present in current master branch (aka latest git).
  • [ x ] I have searched the issue tracker for a similar issue.
  • [ x ] If there is a stack dump, I have decoded it.
  • [ x ] I have filled out all fields below.

Platform

  • Hardware: [ESP-12]
  • Core Version: [3.0.2]
  • Development Env: [Arduino IDE]
  • Operating System: [Windows]

Settings in IDE

  • Module: [Generic ESP8266 Module]
  • Flash Mode: [DOUT]
  • Flash Size: [4MB]
  • lwip Variant: [v2 Lower Memory]
  • Reset Method: [dtr]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200]

Problem Description

I have a separate router and modem.
After temporary data loss (modem disconnected, internet reconnection, etc), without WiFi connection loss ESP DNS cant solve any IP addresses.

I have enabled the DEBUG level to WIFI.

Sketch

#include <ESP8266WiFi.h>

const char* ssid     = "my-ssid";
const char* password = "my-password";

void setup() {
  Serial.begin(115200);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  IPAddress ipResult;
  int result = WiFi.hostByName("www.google.com", ipResult);
  Serial.print("Result: "); Serial.println(result);
  Serial.print("Ip: "); Serial.println(ipResult);
  Serial.println();
  delay(5000);
}

Turn on the router WITHOUT DATA (modem connection), and start the ESP.

The output, as expected, is this:

[hostByName] request IP for: www.google.com
[hostByName] Host: www.google.com lookup error: -5!
Result: 0
Ip: (IP unset)

But after data reestablishing (connecting the router to the modem), ESP still cannot resolve the IP address.

I know there is a DNS cache (I don't know exactly how long it lasts), but I left it running for 24 hours and the output remained the same.

I tried some actions, like reconnecting to WiFi, but is only solves if I restart the device.

@mcspr
Copy link
Collaborator

mcspr commented Dec 31, 2022

Why do you think of cache first? You sure networking works at all?

DNS servers are printable

Serial.println(WiFi.dnsIP(0));
Serial.println(WiFi.dnsIP(1));
Serial.println(WiFi.dnsIP(2));

Same for our own IP, netmask and gateway

Serial.println(WiFi.localIP());
Serial.println(WiFi.subnetMask());
Serial.println(WiFi.gatewayIP());

I'd expect to see something different when it works and when it doesn't

@brunoudi
Copy link
Author

I'm pretty sure the network starts working fine after I connect the router to modem.

I actually did not thing at DNS cache at first, and I also printed the DNS IP as suggested, but when using dhcp the dns usually is the gateway address. So, the IP didn't change when have or not data connection.

If I turn on the ESP with everything Ok (wifi + data), it solves the IP and print.

After removing the conection from router to modem, it continuous printing the IP for a while because of DNS cache (not exactly same time every test), and only after some minutes it begins to show error.

It looks like that when it tries to solve the IP and is not successfull, the device never again tries to actually solve the IP and only returns the error from some kind of cache.

@mcspr
Copy link
Collaborator

mcspr commented Dec 31, 2022

True, DNS client stores the record based on TTL. My question was - is device actually connected, does anything but DNS work?

Error code -5 means IN_PROGRESS, our code just times out the request (edit ...and we should probably replace it with TIMEOUT, since it is what happens)
https://github.com/esp8266/Arduino/search?q=ERR_INPROGRESS&type=code
So at least the request is attempted.

@d-a-v
Copy link
Collaborator

d-a-v commented Jan 1, 2023

Network protocol activity can be traced or debugged with included netdump facility

@d-a-v
Copy link
Collaborator

d-a-v commented Jan 5, 2023

@brunoudi a DNS fix was merged.
Can you retry using current master of this core ?

@d-a-v d-a-v added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Jan 5, 2023
@nilo85
Copy link

nilo85 commented Feb 25, 2024

Edit2: I can confirm it works now that I fixed my non responding IPv4 DNS... (thank you PS5 for not having smart dns solving skills and giving me a second reason to consider something actually being wrong with network)

I seem to have the same issue.

My device gets ip 192.168.68.XX
GW, DNS etc set to 192.168.68.1
My router is a google nest wifi if that makes a difference..

Frustrating =) I tried the both git master and latest stable release with same issue

EDIT: I just found out that my issue seems to be that I f*cked up ipv4 configuration on my first router and no DNS for ipV4 was set properly and google nest dns failed for IPV4. and all my other devices seem to somehow managed to use IPV6 dns to resolve IPv4

@d-a-v
Copy link
Collaborator

d-a-v commented Feb 26, 2024

Can we close this issue ?

@nilo85
Copy link

nilo85 commented Feb 27, 2024

I’m not the original reporting user and don’t know if you have any rules when to close etc, as I found a valid cause to my issue and original reporting user has not replied within a year, I would feel encouraged to close this one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

4 participants