Skip to content

Commit 2cad91a

Browse files
committed
update README and output
Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent 35daf02 commit 2cad91a

File tree

2 files changed

+48
-25
lines changed

2 files changed

+48
-25
lines changed

README.md

+44-21
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,67 @@
11
# dns-resolver
22

33
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+
47
It's mainly written by understanding the contents of https://implement-dns.wizardzines.com/book/intro.html
58
and https://datatracker.ietf.org/doc/html/rfc1035. The primary goal of this project
69
is to understand how DNS works from the ground up and brush up on my Rust skills.
710

811
## Usage
912

13+
### Client
14+
15+
Fetch the A records for google.com:
16+
1017
```bash
11-
❯ cargo run --bin client google.com TXT
18+
❯ cargo run --bin client google.com A
1219

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"]
1724
```
1825

26+
Fetch the CNAME records for www.github.com:
27+
1928
```bash
20-
❯ cargo run --bin client google.com NS
29+
❯ cargo run --bin client www.github.com CNAME
2130

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"]
2635
```
2736

28-
```bash
29-
❯ cargo run --bin client google.com A
37+
### Server
3038

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
3543
```
3644

45+
Open another terminal window and use `dig` to access the server:
46+
3747
```bash
38-
cargo run --bin client www.github.com CNAME
48+
dig @127.0.0.1 -p 3500 google.com A
3949

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
4467
```

src/resolver.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Resolver {
4141

4242
loop {
4343
println!(
44-
"Querying {} for {} about {:?} type",
44+
"Querying {} for {} about record type {:?}",
4545
nameserver, domain, record_type
4646
);
4747
let response = self
@@ -72,7 +72,7 @@ impl Resolver {
7272

7373
loop {
7474
println!(
75-
"Querying {} for {} about {:?} type",
75+
"Querying {} for {} about record type {:?}",
7676
nameserver, domain, record_type
7777
);
7878
let response = self
@@ -102,7 +102,7 @@ impl Resolver {
102102

103103
loop {
104104
println!(
105-
"Querying {} for {} about {:?} type",
105+
"Querying {} for {} about record type {:?}",
106106
nameserver, domain, record_type
107107
);
108108
let response = self
@@ -133,7 +133,7 @@ impl Resolver {
133133

134134
loop {
135135
println!(
136-
"Querying {} for {} about {:?} type",
136+
"Querying {} for {} about record type {:?}",
137137
nameserver, domain, record_type
138138
);
139139
let response = self

0 commit comments

Comments
 (0)