Linux 非常简单的DNS服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11037188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Very simple DNS server
提问by jasonlfunk
I have a linux server has an ad-hoc wireless network for clients to connect to. Once connected I want users to always be redirected to it's own web server no matter what URL they type in. The large solution would be to set up a full DNS server (with BIND or equivalent) but that seems like overkill. All I need is a simple program that will listen for any DNS request and always respond with the same IP address.
我有一个 linux 服务器有一个 ad-hoc 无线网络供客户端连接。一旦连接,我希望用户总是被重定向到它自己的 Web 服务器,无论他们输入什么 URL。主要的解决方案是设置一个完整的 DNS 服务器(使用 BIND 或等效的),但这似乎有点矫枉过正。我所需要的只是一个简单的程序,它将侦听任何 DNS 请求并始终使用相同的 IP 地址进行响应。
I looked around for one but couldn't seem to find one. It would preferably be written in C or Perl as I don't really want to install any other scripting languages.
我环顾四周,但似乎找不到一个。它最好用 C 或 Perl 编写,因为我真的不想安装任何其他脚本语言。
采纳答案by Boris Ivanov
Use Net::DNS::Nameserverand write your own reply handler.
使用Net::DNS::Nameserver并编写您自己的回复处理程序。
For C, look at:
对于 C,请查看:
回答by EricM
I've used fakedns.pywhen reversing malware. It may be too limited for your situation.
我在逆转恶意软件时使用了fakedns.py。对于您的情况,它可能太有限了。
回答by hobbs
I would suggest using dnsmasq. It's more full-featured than you absolutely need, but it's very well-written, small, and easy to install, and the only configuration you would need to give it is --address='/#/1.2.3.4'
to tell it to answer all queries (that don't match some other rule) with the address 1.2.3.4. dnsmasq is well-known and maintained and probably a more robust server than Net::DNS::Nameserver.
我建议使用dnsmasq。它比您绝对需要的功能更全,但它编写得非常好,体积小且易于安装,您需要提供的唯一配置是--address='/#/1.2.3.4'
告诉它回答所有查询(与其他查询不匹配)规则),地址为 1.2.3.4。dnsmasq 是众所周知和维护的,并且可能是比 Net::DNS::Nameserver 更强大的服务器。
回答by nephewtom
As I answered in the other related question, I wrote a basic DNS server in C++ for a job interview under BSD license.
正如我在另一个相关问题中回答的那样,我用 C++ 编写了一个基本的 DNS 服务器,用于在 BSD 许可下进行面试。
I think the code was pretty clean, though I didn't made unit tests :-( I tested it with dig, and it took about a week understanding DNS protocol + implementing + documentation.
我认为代码很干净,尽管我没有进行单元测试:-( 我用 dig 测试了它,大约花了一周时间理解 DNS 协议 + 实现 + 文档。
If anyone would want to extend it, I guess it would not be very difficult. Because I think it only supported inverse queries, as that was asked in the exercise.
如果有人想扩展它,我想这不会很困难。因为我认为它只支持反向查询,正如练习中所问的那样。
The code could be found here: http://code.google.com/p/dns-server/
代码可以在这里找到:http: //code.google.com/p/dns-server/
It was migrated to: https://github.com/tomasorti/dns-server