Search code examples
dnsesp8266arduino-esp8266

Device can't resolve host


I have simple DNS resolve demo in my ESP8266. Can't find why it cat resolve Ubuntu virtual machine on AWS. According to my understanding DNS server is my home router 192.168.1.1. Resolution works fine from my desktop PC while ESP8266 fails. Why and how to fix that?

void printDNSServers() {
  Serial.print("DNS #1, #2 IP: ");
  WiFi.dnsIP().printTo(Serial);
  Serial.print(", ");
  WiFi.dnsIP(1).printTo(Serial);
  Serial.println();
}

void printIPAddressOfHost(const char* host) {
  IPAddress resolvedIP;
  if (!WiFi.hostByName(host, resolvedIP)) {
    DEBUG_LOG("DNS lookup failed.  ");
    DEBUG_LOGLN(host);
  }
  DEBUG_LOGLN(host);
  DEBUG_LOGLN(" IP: ");
  Serial.println(resolvedIP);
}



void loop()
{
  printDNSServers();
  printIPAddressOfHost("yahoo.com");
  printIPAddressOfHost("ec2-34-254-225-201.eu-west-1.compute.amazonaws.com port");
}

Output is:

DNS #1, #2 IP: 192.168.1.1, (IP unset)
yahoo.com
 IP: 
98.138.219.232
DNS lookup failed.  ec2-34-254-225-201.eu-west-1.compute.amazonaws.com port
ec2-34-254-225-201.eu-west-1.compute.amazonaws.com port
 IP: 

Solution

  • You are trying to resolve the following hostname:

    ec2-34-254-225-201.eu-west-1.compute.amazonaws.com port
    

    You need to take the port off the end, as the current string is not a valid hostname.

    ec2-34-254-225-201.eu-west-1.compute.amazonaws.com