Here are a few possible ways to read this, in ascending order of difficulty:
- Just read it, don't run the code
- Read it, and copy the Python snippets as you go to assemble a working DNS resolver
- Translate the Python code into a different language (Javascript! Ruby! Go! Elixir! Rust! Your favourite language here!). I find translating working code into another language to be a really nice balance of difficulty.
- Add extra features (there are some "extra fun" ideas at the end!)
So far people have implemented this project in: Go, C#, C, Clojure, Python, Ruby, Kotlin, Rust, Typescript, Haskell, OCaml, Elixir, Odin, and probably more languages too.
You only need Python >= 3.8. No libraries.
The 3.8 requirement is because I've used dataclasses and the walrus :=
operator a little bit. But if you only have an older version of Python or if
you don't like those newer features it should also be pretty straightforward to
modify the code to make it run with any Python version, even Python 2. All you
really need are the socket
and struct
modules which have been in Python
forever.
I've tested this code on Mac and Linux, but not on Windows. It shouldn't be too hard to make it work on Windows too though.
Beta testers of this guide have reported that it takes around 2-4 hours to do it in Python, and more if you're translating it to another language.
No specific requirements, other than being somewhat comfortable in Python! I'd encourage you to try this out even if you're new to DNS and parsing binary formats. I think writing code is a nice way to learn about some of the concepts.
If you get stuck or confused, here are some resources to learn a little more about DNS:
free resources:
- my many DNS blog posts
- my talk Learning DNS in 10 Years
- this dns comic
paid resources:
- my How DNS Works zine
Finally: this is a toy implementation that barely works, not a guide to writing production DNS software. I've never written production DNS software and don't have any advice about how to do it well, but it's definitely not like this. A couple of links:
- this long list of RFCs related to DNS gives you a sense for DNS's actual complexity
- hello DNS from PowerDNS has a teaching implementation that focuses more on standards compliance and correctness