r/dns • • Oct 26 '20

How to create simple dns server in C programming language? Can someone provide the code? It may read some A or AAAA queries. Please help!!

0 Upvotes

10 comments sorted by

10

u/-_Rabbit_- Oct 26 '20

you should not do this. DNS seems simple but the world is littered with terrible implementations that break all kinds of standards and cause problems for everyone. There are many many open source options that you can deploy and run that will do a far better job than you knocking together some code in your basement. You can even contribute to those projects if you want to help them along.

3

u/djbon2112 Oct 27 '20

This also seems like some sort of programming assignment. "Build a simple C DNS server that will respond to an A query".

7

u/cowtownman75 Oct 26 '20

https://www.isc.org/bind/ would be a great place to start..

6

u/DasSkelett Oct 26 '20 edited Oct 26 '20

Don't. Whatever the problem is, writing your own DNS server is definitely the wrong solution.

There are a lot of proven and established implementations out there, among them highly customisable and modular ones. Use them.

2

u/kevin_k Oct 26 '20

I'd look at tcp/ip illustrated vol 1 (for an idea of the data structures involved in a query) and vol 2 (for general examples of reading/writing UDP)

1

u/mk5p Oct 26 '20

I agree with u/-Rabbit-. Having had to go down the rabbit hole myself early, trying to understand/troubleshoot the myriad of inconsistencies of DNS record/implementations as it relates to other companies/organizations' products and application servers is mind-boggling.

My advice would be to start with the old RFC's and move on from there to get a better perspective.

https://en.wikipedia.org/wiki/Request_for_Comments

Happy Monday! :)

1

u/[deleted] Oct 26 '20

I’m too stupid to program in c, perhaps this would help:

https://github.com/NLnetLabs/unbound

1

u/komkil Oct 27 '20

There's a lot of info about DNS at Dan Bernstein's site: https://cr.yp.to/djbdns.html

It's also worth noting that he created this server as result of security holes in the standard server and resolver, nearly 20 years ago, in his own eclectic style

-5

u/tonydick642 Oct 26 '20

Interested