Contacting DNS server via command line interface [closed]
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.)
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.
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!
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'