Git Product home page Git Product logo

simpledns's Introduction

Introduction

SimpleDNS is a very simple DNS server written in C. It was made to learn the basics of the DNS protocol.

Features:

  • very small
  • single-threaded
  • very simplistic memory management
  • supports A, AAAA and TXT queries
  • no full protection against invalid requests :|

Build

git clone https://github.com/mwarning/SimpleDNS.git
cd SimpleDNS
make

Test

Start SimpleDNS:

$./main
Listening on port 9000.

In another console execute dig to make a DNS request:

$ dig @127.0.0.1 -p 9000 foo.bar.com A

; <<>> DiG 9.8.4-rpz2+rl005.12-P1 <<>> @127.0.0.1 -p 9000 foo.bar.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 15287
;; flags: qr; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;foo.bar.com.                   IN      A

;; ANSWER SECTION:
foo.bar.com.            0       IN      A       192.168.1.1

;; Query time: 0 msec
;; SERVER: 127.0.0.1#9000(127.0.0.1)
;; WHEN: Mon Apr 15 00:50:38 2013
;; MSG SIZE  rcvd: 56

Note:

  • On Debian Linux, dig is part of the dnsutils package.
  • Use AAAA instead of A in the dig command line to request the IPv6 address.

Modify address entries

The code maps the domain foo.bar.com to the IPv4 address 192.168.1.1 and IPv6 address fe80::1. It is easy to find it in the code and to add other entries.

Recommended Reading

The DNS section of the TCP/IP-Guide was very helpful for understanding the protocol.

Similar Projects

simpledns's People

Contributors

chmorgan avatar clementperon avatar glennwang avatar mwarning avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simpledns's Issues

How can I trace the CNAME record until the A record is obtained ?

Would you have time to have a look at my problem?

Basied on your demo program, I get the result:

My result:

dig cname.ihih.ml

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> cname.ihih.ml
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58442
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;cname.ihih.ml.			IN	A

;; Query time: 110 msec
;; SERVER: 100.100.2.138#53(100.100.2.138)
;; WHEN: 一 3月 02 18:54:46 CST 2020
;; MSG SIZE  rcvd: 42

-----------------------------------------------------

dig cname.ihih.ml cname

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> cname.ihih.ml cname
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9014
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;cname.ihih.ml.			IN	CNAME

;; ANSWER SECTION:
cname.ihih.ml.		19	IN	CNAME	www.infoch.cn.

;; Query time: 4 msec
;; SERVER: 100.100.2.138#53(100.100.2.138)
;; WHEN: 一 3月 02 18:55:02 CST 2020
;; MSG SIZE  rcvd: 69

---------------------------------------------------------------

dig www.infoch.cn

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> www.infoch.cn
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28656
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.infoch.cn.			IN	A

;; ANSWER SECTION:
www.infoch.cn.		270	IN	A	58.51.101.160

;; Query time: 0 msec
;; SERVER: 100.100.2.138#53(100.100.2.138)
;; WHEN: 一 3月 02 18:55:14 CST 2020
;; MSG SIZE  rcvd: 58

The expected result looks like the following:

dig www.baidu.com

; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7_5.1 <<>> www.baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24746
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.baidu.com.			IN	A

;; ANSWER SECTION:
www.baidu.com.		1195	IN	CNAME	www.a.shifen.com.
www.a.shifen.com.	123	IN	A	220.181.38.149
www.a.shifen.com.	123	IN	A	220.181.38.150

;; Query time: 0 msec
;; SERVER: 100.100.2.138#53(100.100.2.138)
;; WHEN: 一 3月 02 18:46:00 CST 2020
;; MSG SIZE  rcvd: 90

support TXT

Could you implement TXT ?

I'm learning DNS program and reading your code.

I add code to support TXT, but the answer can not be parsed successfully by dig.

On the implementation of decode_domain_name

Hi mwarning,

I am wondering why the follow section would work

(https://github.com/mwarning/SimpleDNS/blob/5bdd512af5fa750fd55c28c7c04d74c40ae0ef2d/main.c#L339-L341)

Let's say the domain name in query is foo-bar.example.com, its encoded version is 7foo-bar6example3com0. Since the ASCII code of - is 45, which is not greater than 63, won't it be decoded to foo.bar.example.com by your current implementation?

( I do notice that you stated "No full validation is done!", but I am not sure if the issue I just point out is also expected)

Alex

Multi name server

There is more than one name server record generally.

For example:
ns1.foo.bar.
ns2.foo.bar.

How the name_server_record struct support this condition ?

const RA_MASK seems incorrect

Hi mwarning,

It seems to me that the const RA_MASK's value defined here (

static const uint32_t RA_MASK = 0x8000;
) is incorrect. According to my understanding of the DNS protocol, the constant should be 0b0000000010000000 (or 0x80) instead of 0x8000 (or 0b1000000000000000).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.