Making a DNS query in Ruby from scratch

191 · Julia Evans · Nov. 6, 2022, 4:30 p.m.
Hello! A while back I wrote a post about how to write a toy DNS resolver in Go. In that post I left out “how to generate and parse DNS queries” because I thought it was boring, but a few people pointed out that they did not know how to parse and generate DNS queries and they were interested in how to do it. This made me curious – how much work is it do the DNS parsing? It turns out we can do it in a pretty nice 120-line Ruby program, which is not that bad. So here’s a quick post on how to genera...