-
Notifications
You must be signed in to change notification settings - Fork 7.6k
WiFi + Ethernet (LAN8720): DNS Server Managment #7602
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
Comments
@me-no-dev not sure if it's "just that". Because as you can see in my tests, Ethernet does not work if you power on everything with the Ethernet cable plugged and just calling ETH.begin() and WiFi.begin() with an unexistent SSID. As you can see, that particular bug occurs without calling any config(). So I think the bug it's a bit more complex. It's not just the setters and getters of the DNS servers. It's the way Ethernet and Wifi initializes. If I just call ETH.begin() without calling WiFi.begin() it works right away (with the Ethernet cable plugged before powering up). But if you call WiFi.begin() with an unexistent SSID right after ETH.begin() the DNS resolution starts to fail. So I think WiFi.begin() is also messing with the Ethernet DNS. The only way to fix this bug is to call both config() methods as stated on the bug report. |
When closing WiFi, you also erase the DNS entries. What I do in ESPEasy as a work-around is that I keep a copy of the received DNS records from the DHCP. Typical use case:
|
I have done some more research on this topic. For sure the DNS server IPs get reset (or set to some random value) when the WiFi interface is turned off. On the latest SDK revisions, things have changed for the worse. Another change is that this mangling of the DNS server IPs is done on every DHCP lease renewal. So not only is it a really poor design decision to only have a single set of DNS IPs instead of per interface, but also clearing it when shutting down one interface will mess up the DNS config of another. Also the DHCP lease renewal apparently differs from the initial DHCP request. The work-around I just implemented for ESPEasy is to cache the DNS server IPs per interface. If/When someone is going to look into this, I would also make a feature request to get access to some extra DHCP optional fields, like syslog server IP and NTP server IP. |
The limitation comes from LWIP which uses the same pair of DNS servers for all interfaces, whether IPv4 or IPv6. In Tasmota, I had to make sure that we keep a copy of 2x DNS IPv4 and 2x DNS IPv6 servers, and force them back in place whenever LWIP clears them. |
Ah, that's even nastier. Did not realize you only had the same 2 for both IPv4 and IPv6. |
No you can't. The resolver always prefers the first one and moved to second if the first times out |
@VojtechBartoska @me-no-dev Can this bug added too milestone 2.0.7? |
@Jason2866 it will not make it to 2.0.7 unless someone submits a PR with fixes. We already have quite a bit to look into and 2.0.7 needs to come out fast |
Ahh, okay. Sorry no PR to fix. |
Possibly related #8672 |
Hi @gonzabrusco is this still valid in version 2.0.14? Can you please test if you still face the issue on latest release of 2.X? Thanks |
This will be probably covered by #8760 |
Sorry. I can't test it right now. I will let you know later or when 3.0.0 is released. @VojtechBartoska |
Hello, can you please validate this against 3.0.0-RC1 version? Thanks |
This is supposed to be solved, I am closing this ticket. If needed, you can reopen. Thanks. |
Board
Custom ESP32 Board with a LAN8720
Device Description
Custom ESP32 Board with a LAN8720
Hardware Configuration
Custom ESP32 Board with a LAN8720
Version
v2.0.5
IDE Name
PlatformIO
Operating System
Windows 10
Flash frequency
40MHz
PSRAM enabled
no
Upload speed
115200
Description
Hello. I'm doing some tests with a custom board with the LAN8720 onboard.
I noticed that ETH.dnsIP(uint8_t dns_no) and WiFi.dnsIP(uint8_t dns_no) always return the same IPs. I think there's a problem in the way the DNS are being handled. Is it normal for both interfaces to share the same DNS?
The DNS set are always the ones of the latest interface that got IP (by DHCP). For example take a look at the following screenshot:
As you can see, the IP of the Ethernet and the WiFi interface are different, but the DNS are the same for some reason. In that image, the Ethernet connected first and then the WiFi, overriding the DNS that got Ethernet first (which does not make sense because those IPs are not even in the same subnet of the Ethernet IP).
Also I noticed another problem while using both interfaces at the same time. If the network cable is plugged before powering everything up, I can't never connect to my server using the following code:
The error the debug gives me is:
E][WiFiGeneric.cpp:1438] hostByName(): DNS Failed for test.mosquitto.org
The only way for this to start working, if by unplugging and plugging the Ethernet cable. Just then the DNS are set correctly.
But if I modify the code and add some lines, Ethernet works from the start (without needing to unplug and plug the Ethernet cable):
This clearly seems like a bug or a bad managment of DNS servers. If DNS are shared, then it this means that Ethernet and WiFi can't be used together on the first place. And even if that was not possible, when running WiFi.begin() without a previous config, seems to reset or delete the DNS of the Ethernet interface.
Finally as a bonus bug WiFiClientSecure localIP() method always returns 0.0.255.0 but if I modify the script to connect without TLS, the localIP() method works fine on a regular WiFiClient.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: