A guide to writing a DNS Server from scratch in Rust
Go to file
Emil Hernvall 4a7b7bea93
Merge pull request #27 from NenX/master
examples: fix incorrect hexadecimal representation
2024-09-09 09:43:57 +02:00
examples examples: fix incorrect hexadecimal representation 2024-09-09 10:15:23 +08:00
.gitignore Modernize samples 2020-06-18 00:47:06 +02:00
Cargo.lock Modernize samples 2020-06-18 00:47:06 +02:00
Cargo.toml Modernize samples 2020-06-18 00:47:06 +02:00
chapter1.md removing stale comment 2023-01-29 14:47:24 -08:00
chapter2.md Fix typo in label max length 2020-12-07 00:52:35 +01:00
chapter3.md Update examples with modernized code 2020-06-18 01:50:29 +02:00
chapter4.md fix typo 2020-11-28 19:26:08 +06:00
chapter5.md Eliminate all useless allocation 2020-06-18 02:23:42 +02:00
LICENSE Create LICENSE 2021-05-03 23:55:32 +02:00
README.md use relative links in README.md 2024-07-08 11:54:14 -04:00

Building a DNS server in Rust

The internet has a rich conceptual foundation, with many exciting ideas that enable it to function as we know it. One of the really cool ones is DNS. Before it was invented, everyone on the internet - which admittedly wasn't that many at that stage - relied on a shared file called HOSTS.TXT, maintained by the Stanford Research Institute. This file was synchronized manually through FTP, and as the number of hosts grew, so did the rate of change and the unfeasibility of the system. In 1983, Paul Mockapetris set out to find a long term solution to the problem and went on to design and implement DNS. It's a testament to his genius that his creation has been able to scale from a few thousand computers to the Internet as we know it today.

With the combined goal of gaining a deep understanding of DNS, of doing something interesting with Rust, and of scratching some of my own itches, I originally set out to implement my own DNS server. This document is not a truthful chronicle of that journey, but rather an idealized version of it, without all the detours I ended up taking. We'll gradually implement a full DNS server, starting from first principles.

Samples

Each chapter has a corresponding sample which contains the full code up to that point in the guide, named sample1.rs through sample5.rs. These can be run using, for first chapter, cargo run --example sample1.

Revision History

  • June 2020 - Fixed a security vulnerability in read_qname which allowed for a malicious packet to trigger an infinite loop. Modernized the code to conform to current rust practices, and fixed various ugly inefficiencies.
  • July 2016 - Initial version