wiki

Help! I'm trapped in a wiki!

Site Tools


programs:dig

dig

dig can be used to make DNS queries.

🔹️ dig [options] @server name type

server is the nameserver to query (1.1.1.1) name is what it should query (costiser.ro) type is how it should query (A, NS, MX, …)

For example, dig costiser.ro A returns costiser.ro. 300 IN A 104.21.51.8, which means costiser.ro: - has the IP address of 104.21.51.8 - it has a cache time of 300s (the DNS resolver remembers it for 300s, then asks a higher-up nameserver)

Most of the time you’re only interested in the answer portion of dig’s output, so you can make a .digrc file in your home folder and include +noall +answer in it. To view all the output just run dig with +all.

You can use +trace to simulate a recursive DNS resolver’s requests. It starts from the root nameservers and goes down the DNS hierarchy until it reaches the SOA for that domain.


Fun stuff

jvns made a dns query-er in Ruby here. Logic and code could be adapted to C# or python maybe, will have to see. The gist of it is this:

  • open a UDP socket
  • learn what a DNS query looks one (header and question)
  • make the header (query ID, the flags, number of questions, answer records, authoritative records, and additional records)
  • make the question (domain name, query type, query class)
  • encode domain name to DNS format
  • make the query-sending function

And that’s it! You can (should) also make a DNS parser, which takes a DNS response and processes it into something actually useful (i.e. domain name → IP address) It needs to:

  • parse the DNS header
  • parse the domain name
  • then implement DNS compression
  • parse the DNS query
  • parse the DNS record
programs/dig.txt · Last modified: by 127.0.0.1