|
1 | 1 | # dns-resolver
|
2 | 2 |
|
3 | 3 | dns-resolver is a toy DNS resolver. It can handle A, NS, CNAME and TXT records.
|
| 4 | +Its a recursive resolver that can be used as DNS client or server. The server supports |
| 5 | +caching via a fixed size LRU cache. |
| 6 | + |
4 | 7 | It's mainly written by understanding the contents of https://implement-dns.wizardzines.com/book/intro.html
|
5 | 8 | and https://datatracker.ietf.org/doc/html/rfc1035. The primary goal of this project
|
6 | 9 | is to understand how DNS works from the ground up and brush up on my Rust skills.
|
7 | 10 |
|
8 | 11 | ## Usage
|
9 | 12 |
|
| 13 | +### Client |
| 14 | + |
| 15 | +Fetch the A records for google.com: |
| 16 | + |
10 | 17 | ```bash
|
11 |
| -❯ cargo run --bin client google.com TXT |
| 18 | +❯ cargo run --bin client google.com A |
12 | 19 |
|
13 |
| -Querying 198.41.0.4 for google.com about TXT type |
14 |
| -Querying 192.12.94.30 for google.com about TXT type |
15 |
| -Querying 216.239.34.10 for google.com about TXT type |
16 |
| -answer(s): ["atlassian-domain-verification=5YjTmWmjI92ewqkx2oXmBaD60Td9zWon9r6eakvHX6B77zzkFQto8PQ9QsKnbf4I", "facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95", "globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8=", "MS=E4A68B9AB2BB9670BCE15412F62916164C0B20BB", "v=spf1 include:_spf.google.com ~all", "google-site-verification=TV9-DBe4R80X4v0M4U_bd_J9cpOJM0nikft0jAgjmsQ"] |
| 20 | +Querying 198.41.0.4 for google.com about record type A |
| 21 | +Querying 192.12.94.30 for google.com about record type A |
| 22 | +Querying 216.239.34.10 for google.com about record type A |
| 23 | +answer(s): ["142.250.76.174"] |
17 | 24 | ```
|
18 | 25 |
|
| 26 | +Fetch the CNAME records for www.github.com: |
| 27 | + |
19 | 28 | ```bash
|
20 |
| -❯ cargo run --bin client google.com NS |
| 29 | +❯ cargo run --bin client www.github.com CNAME |
21 | 30 |
|
22 |
| -Querying 198.41.0.4 for google.com about NS type |
23 |
| -Querying 192.12.94.30 for google.com about NS type |
24 |
| -Querying 216.239.34.10 for google.com about NS type |
25 |
| -answer(s): ["ns1.google.com", "ns3.google.com", "ns4.google.com", "ns2.google.com"] |
| 31 | +Querying 198.41.0.4 for www.github.com about record type CNAME |
| 32 | +Querying 192.12.94.30 for www.github.com about record type CNAME |
| 33 | +Querying 205.251.193.165 for www.github.com about record type CNAME |
| 34 | +answer(s): ["github.com"] |
26 | 35 | ```
|
27 | 36 |
|
28 |
| -```bash |
29 |
| -❯ cargo run --bin client google.com A |
| 37 | +### Server |
30 | 38 |
|
31 |
| -Querying 198.41.0.4 for google.com about A type |
32 |
| -Querying 192.12.94.30 for google.com about A type |
33 |
| -Querying 216.239.34.10 for google.com about A type |
34 |
| -answer(s): ["74.125.24.101", "74.125.24.139", "74.125.24.138", "74.125.24.113", "74.125.24.102", "74.125.24.100"] |
| 39 | +Run the server: |
| 40 | + |
| 41 | +```bash |
| 42 | +❯ cargo run --bin server |
35 | 43 | ```
|
36 | 44 |
|
| 45 | +Open another terminal window and use `dig` to access the server: |
| 46 | + |
37 | 47 | ```bash
|
38 |
| -❯ cargo run --bin client www.github.com CNAME |
| 48 | +❯ dig @127.0.0.1 -p 3500 google.com A |
39 | 49 |
|
40 |
| -Querying 198.41.0.4 for www.github.com about CNAME type |
41 |
| -Querying 192.12.94.30 for www.github.com about CNAME type |
42 |
| -Querying 205.251.193.165 for www.github.com about CNAME type |
43 |
| -answer(s): ["github.com"] |
| 50 | +; <<>> DiG 9.10.6 <<>> @127.0.0.1 -p 3500 google.com A |
| 51 | +; (1 server found) |
| 52 | +;; global options: +cmd |
| 53 | +;; Got answer: |
| 54 | +;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34233 |
| 55 | +;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 |
| 56 | +
|
| 57 | +;; QUESTION SECTION: |
| 58 | +;google.com. IN A |
| 59 | +
|
| 60 | +;; ANSWER SECTION: |
| 61 | +google.com. 300 IN A 142.250.67.206 |
| 62 | +
|
| 63 | +;; Query time: 305 msec |
| 64 | +;; SERVER: 127.0.0.1#3500(127.0.0.1) |
| 65 | +;; WHEN: Mon Jan 08 01:37:32 IST 2024 |
| 66 | +;; MSG SIZE rcvd: 44 |
44 | 67 | ```
|
0 commit comments