2

I'm trying to build a little project using the Arduino Ethernet library, but I'm having a weird DNS issue:

It cannot resolve any domain name that is local to my network, but it has no problem resolving public domain names.

No other system on my network has problems with these local domain names. It just seems to be the Arduino.

Here's what I'm using:

Here's my test sketch:

#include <SPI.h>
#include <Ethernet.h>
#include <Dns.h>
#include <EthernetUdp.h>

byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

EthernetClient client;

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

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    while(true);
  }

  delay(1000);
  Serial.println("connecting...");
  DNSClient dnsClient;

  // Router IP address
  byte dnsIp[] = {192, 168, 11, 1};

  dnsClient.begin(dnsIp);

  // Regular DNS names work...
  IPAddress ip1;
  dnsClient.getHostByName("www.google.com", ip1);
  Serial.print("www.google.com: ");
  Serial.println(ip1);

  // However local ones defined by my router do not (but they work fine everywhere else)...
  IPAddress ip2;
  dnsClient.getHostByName("Tycho.localnet", ip2);
  Serial.print("Tycho.localnet: ");
  Serial.println(ip2);
}

void loop() {

}

Here's its output (the second IP address is incorrect):

connecting...
www.google.com: 74.125.227.84
Tycho.localnet: 195.158.0.0

Here's the correct information given from a Linux machine connected to the same network:

$ nslookup www.google.com
Server:         192.168.11.1
Address:        192.168.11.1#53

Non-authoritative answer:
Name:   www.google.com
Address: 74.125.227.80
Name:   www.google.com
Address: 74.125.227.84
Name:   www.google.com
Address: 74.125.227.82
Name:   www.google.com
Address: 74.125.227.83
Name:   www.google.com
Address: 74.125.227.81

$ nslookup Tycho.localnet
Server:         192.168.11.1
Address:        192.168.11.1#53

Name:   Tycho.localnet
Address: 192.168.11.2

What's going on?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kaypro II
  • 3,210
  • 8
  • 30
  • 41

2 Answers2

2

I don't know if you've already found a solution, but just in case:

There's a defect in inet_aton which is part of the DNS library:

This is supposed to convert a string IP address to the IPAddress type.

To find out it tests each character in the string for numerals:

while (*p &&
       ( (*p == '.') || (*p >= '0') || (*p <= '9') ))

but any alphabetic character matches *p >= '0'

It should be:

while (*p &&
       ( (*p == '.') || ((*p >= '0') && (*p <= '9')) ))

You need to change this in Dns.cpp.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nottledim
  • 85
  • 1
  • 8
0

Many routers will provide their LAN side IP address as the DNS address -- that is typical behavior for DHCP setups. That does not necessarily mean they are actually the server. Some simply forward the DNS requests to the WAN side servers and return the response. This type of configuration where the router is only a proxy explains your symptoms.

When the router is a proxy, the Arduino DNS requests are just being forwarded to the external DNS server which does not know your local names.

The Linux machine is using other network protocols to discover local names. The same thing happens with Windows machines where local computer names are known. If you run a network monitor like Wireshark, you will see computers regularly announcing their presence to other computers. The Arduino only has simple TCP/IP and does not process these broadcasts.

If the router is truly a server, then you must be configuring a table with the entries of name to IP address mapping. To make this work, you cannot use dynamic addresses because what you type into the table one day would be invalid another. To make a local DNS server work with DHCP you would want to lock each computers IP address, either at the computer side, or at the router by linking specific MAC addresses to specific IP addresses.

jdr5ca
  • 2,809
  • 14
  • 25
  • So, what are these "other network protocols" that the Linux machine is using to do lookups? My understanding is that my router is capturing these announcements and making them available via DNS, since they can be queried using standard DNS tools. – Kaypro II Aug 10 '13 at 03:04
  • Others along the lines of LDAP, Samba, DLNA, Bonjour. My Linux boxes can see the Windows box names, I presume through Samba. Two different NAS boxes can run LDAP servers. All these things are broadcasting among themselves announcing services. The hosts file will add items to nslookup. There is a lot more running on a desktop than on an Arduino. – jdr5ca Aug 10 '13 at 05:47