14

So, we are on the DNS chapter in our class, and I was wondering if there's any way possible though which I can connect to a DNS server on port 53 via command line interface (i.e Telnet or netcat) like we do for SMTP or HTTP or POP on their specific ports; I tried:

> telnet 8.8.8.8 53

But the connection was closed as soon as it was established; which I later realized was because telnet uses TCP while DNS uses UDP.

Then I tried doing the same with netcat:

> nc -u 8.8.8.8 53

Nada! I just want to see the working of DNS with some transparency.(like with http, SMTP etc.)

1
  • 3
    I don't know what using telnet would teach you about DNS, but you can certainly query a DNS server from the command line. In Windows you'd use nslookup (with debug to see detailed information). In Linux I believe you'd use dig.
    – joeqwerty
    Commented Oct 23, 2015 at 16:27

3 Answers 3

24

As you note, DNS primarily uses UDP but service is actually also provided over TCP (typically used for large responses and zone transfers).
This is why you managed to establish a connection in the first place when you tried telnet. Your connection was closed because you weren't interacting with the service in the expected way, not because telnet uses TCP.

The important difference is that, unlike HTTP and SMTP which are plain text protocols and easy enough to work with directly, DNS is a binary protocol.

This means that you will need some DNS client program to interact with nameservers in any reasonable fashion.

dig has been the de facto standard for DNS troubleshooting for a very long time as it is very good in terms of both constructing queries and in terms of pretty-printing all the information in the response in a concise way. (Part of BIND code-base and included in the Windows build from ISC.)

drill is another alternative with similar capabilities and essentially the same output formatting as dig.

nslookup is well known as it has been around since the dawn of time. It has been largely abandoned except on Windows and has some undesirable quirks and limited capabilities in comparison to the previously mentioned alternatives. The debug option (set debug) makes it usable for troubleshooting in a pinch as it greatly improves the completeness of the output, although the formatting of the debug output leaves a lot to be desired.

4
  • Thank-you for your answer sir, but if I may ask, can you provide some additional info or link on but the service is actually also provided over TCP
    – Jarwin
    Commented Dec 13, 2015 at 20:18
  • @Jarwin Sure, link added. Commented Dec 13, 2015 at 21:33
  • can you also place a link or more information about the binary format used in UDP (/TCP) ?
    – nl-x
    Commented Mar 24, 2017 at 13:38
  • @nl-x Link added Commented Apr 1, 2017 at 19:05
15

You can use the dig utility, like this:

dig @your.dns.server www.foo.bar

Example:

dig @8.8.8.8 www.google.com

If you want to see the step-by-step name resolution, you can do this:

dig +add +trace @8.8.8.8 www.google.com

Best regards!

4
3

For Windows you can use NSlookup

   nslookup [-opt ...]             # interactive mode using default server
   nslookup [-opt ...] - server    # interactive mode using 'server'
   nslookup [-opt ...] host        # just look up 'host' using default server
   nslookup [-opt ...] host server # just look up 'host' using 'server'

Not the answer you're looking for? Browse other questions tagged .