一个简单的 DNS 服务器
我必须用 C 语言实现一个 DNS 服务器,但我不知道从哪里开始。 DNS 具有哪些功能...我如何在单个 C 文件中实现简单的 DNS。
我什至不想使用数据库,只需一个文件即可。
先感谢您
I have to implement a DNS server in C and I don't know where to start. What are all the features that a DNS has...how can I implement a bare-bones DNS in single C file.
I don't even want to use a Database, just a file will work.
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这对于家庭作业来说太重要了!你的老师很有野心。实施 DNS
需要阅读至少 10 个复杂的 RFC(更不用说 DNSSEC...)
不将自己限制在 RFC 1034 和 1035 中,有强制
RFC之后(例如2181和2671)。请参阅其中的漂亮图表。
它是权威名称服务器还是递归名称服务器?
必须从头开始做吗?如果没有,我强烈建议开始
使用 evldns 库,它允许您编写
200 行 C 语言中的 anthoritative 名称服务器。
否则,通常的建议适用:阅读源代码(我建议
nsd 用于权威服务器和 未绑定 用于递归
一)。
That's big for homework! Your teacher is ambitious. Implementing DNS
requires reading at least ten complicated RFC (not mentioning DNSSEC...) Do
not limit yourself to RFC 1034 and 1035, there are mandatory
RFC after (such as 2181 and 2671). See a nice graph of them.
Is it an authoritative name server or a recursive one?
Do you have to do it from scratch? If not, I strongly suggest to start
with the evldns library, which allows you to write an
anthoritative name server in 200 lines of C.
Otherwise, the usual advice applies: read source code (I suggest
nsd for an authoritative server and unbound for a recursive
one).
DNS 是一个大规范。如果您确实需要 DNS,请使用 DNS 服务器。因此,如果您想要一些非常快速和肮脏的东西,为什么不编写一个编辑主机文件的程序(C:\windows\system32\drivers\etc\hosts 或 /etc/hosts(在 UNIX 上)?)
DNS is a big spec. If you really want DNS, use a DNS server. So if you want something really quick and dirty, why not just write a program that edits your hosts file (C:\windows\system32\drivers\etc\hosts or /etc/hosts (on UNIX)?)
这应该可以帮助您开始。
此示例使用 BSD 套接字构建一个简单的 DNS 解析器。
http://www. binarytides.com/blog/dns-query-code-in-c-with-winsock-and-linux-sockets/
This should get you started.
This example uses BSD sockets to build a simple DNS resolver.
http://www.binarytides.com/blog/dns-query-code-in-c-with-winsock-and-linux-sockets/
dns.net 点 RFC 1034:域名 - 概念和设施 和 RFC 1035:域名 - 实施和规范作为最终参考。
作为主题补充,请添加一些 您的玩具查找列表中的非 ASCII IDN 名称。
dns.net points up RFC 1034: DOMAIN NAMES - CONCEPTS AND FACILITIES and RFC 1035: DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION as the definitive references.
As a topical plus, wow your teacher by including some non-ascii IDN names in your toy lookup list.
可以在此处找到该协议所基于的 RFC:http://www.zoneedit.com/ doc/rfc/
在互联网上还可以找到一些对该协议有用的解释,例如:http://www.windowsnetworking.com/articles_tutorials/Understanding-DNS-Protocol-Part1.html
The RFCs that the protocol is based on can be found here: http://www.zoneedit.com/doc/rfc/
There are also several explanations of the protocol that should be useful to be found around the internet, such as this one: http://www.windowsnetworking.com/articles_tutorials/Understanding-DNS-Protocol-Part1.html