Introducing “Implement DNS in a Weekend”

Whats up! I’m excited to announce a undertaking I’ve been engaged on for a very long time:
a free information to implementing your individual DNS resolver in a weekend.

The entire thing is about 200 strains of Python, together with implementing the entire
binary DNS parsing from scratch. Right here’s the hyperlink:

This undertaking is a enjoyable method to be taught:

  • Easy methods to parse a binary community protocol like DNS
  • How DNS works behind the scenes (what’s truly occurring once you make a DNS question?)

The testers have reported that it takes round 2-4 hours to do in Python.

what’s a DNS resolver?

A DNS resolver is a program that is aware of how to determine what the IP tackle
for a website is. Right here’s what the command line interface of the resolver you’ll
write appears to be like like:

$ python3

implementing DNS provides me an incredible sense of confidence

In Studying DNS in 10 years, I
talked about how having applied a toy model of DNS myself from scratch provides
me an unparalleled sense of confidence in my understanding of DNS.

So this information is my try to share that sense of confidence with you all.

Additionally, in case you’ve purchased How DNS Works, I feel
this information is a pleasant companion – you may implement your individual DNS
resolver to solidify your understanding of the ideas within the zine.

it’s a Jupyter pocket book

On this information, I wished to combine code that you possibly can run with explanations. I
struggled to determine the best format for months, after which I lastly thought
of utilizing a Jupyter pocket book! This meant that I might simply test that every one of
the code truly ran.

I used Jupyter Guide to transform the Jupyter notebooks
into an internet site. It reruns the pocket book earlier than changing it to HTML, so I might
simply assure that the entire code truly runs and outputs what it says
that it outputs. I ended up hacking the theme lots to make it extra minimal, as
effectively as doing a little horrible issues with Stunning Soup to get a desk of
contents that exhibits you the worldwide TOC in addition to the web page’s native part
headings multi functional place.

You can even obtain the Jupyter notebooks and run them by yourself laptop
in case you’d like, utilizing the “obtain the code” button on the homepage.

why Python?

I used Python for this information as an alternative of a lower-level language like Go or Rust
to make it extra approachable – once I began studying networking 10 years
in the past, I didn’t actually know any methods languages effectively, and I discovered them form of
intimidating. Implementing traceroute utilizing scapy in Python felt
a lot much less scary.

You possibly can very simply pack/unpack binary information in Python with struct.pack and
struct.unpack, so Python being a higher-level language doesn’t actually trigger
any issues.

The thought is that you could both observe the information in Python (which is the
best mode), or if you would like a much bigger problem, you may translate the code to
any language you’d like. (Go? Javascript? Rust? Bash? Lua? Ruby?)

solely the usual library

It was vital to me to essentially present tips on how to implement DNS “from scratch”, so
the information solely makes use of a couple of very primary customary library modules: struct,
socket, io, random, and dataclasses.

Right here’s what we use every module for:

  • random is used for producing DNS question IDs
  • socket is used to make a UDP connection
  • struct is used for changing to/from binary (struct.pack and struct.unpack)
  • dataclasses are used to make serializing / deserializing data a little bit extra ergonomic
  • io is used for BytesIO, which provides us a reader interface which shops a
    pointer to how a lot of the packet we’ve learn up to now. If I had been implementing
    DNS in a language that didn’t have this type of reader interface, I’d
    implement my very own.

it consists of some bonus workouts

The toy DNS resolver is clearly lacking a bunch of vital options, so
I’ve added some workouts on the finish with examples of options you possibly can add
(and bugs you possibly can repair) to make it a little bit extra like a “actual” DNS resolver.

This checklist isn’t notably exhaustive although, and I’d love to listen to different
concepts for relatively-easy-to-implement DNS resolver options I’ve missed.

subsequent purpose: TLS

I’ve truly written toy implementations of a bunch of different community protocols
in Python (ICMP, UDP, TCP, HTTP, and TLS), and I’m hoping to launch “Implement
TLS in a weekend” sooner or later.

No guarantees although – I’ve one other zine to complete writing first (on all of the
stunning issues about how integers and floats work on computer systems), and a toy
TLS implementation is sort of a bit extra concerned than a toy DNS implementation.

because of the beta testers

Because of everybody (Atticus, Miccah, Enric, Ben, Ben, Maryanne, Adam, Jordan,
and anybody else I missed) who examined this information and reported complicated or
lacking explanations, errors, and typos.

Additionally an enormous because of my buddy Allison Kaptur who designed the primary “Area
Title Saturday” workshop with me on the Recurse Middle in 2020.

The title was impressed by Ray Tracing in One Weekend.

Right here’s the hyperlink to the information once more in case you’d wish to strive it out:

Learn Extra

The put up Introducing “Implement DNS in a Weekend” appeared first on BIRMINGHAM DAILY JOURNAL.