Fake DNS in C

fdns.c is a fake DNS daemon that returns the same IP address for any DNS request. This is very useful if you want to redirect everybody on your LAN to the same web server for instance or to test your web site.

There are other ways to do so, for instance you can setup bind to do so but it’s not very easy.

There is also the python script from (http://code.activestate.com/recipes/491264-mini-fake-dns-server) but relying on python to answer DNS request seems overkill since I plan to use it on a DNS-313 NAS turned in server.

So here’s my contribution, a simple C program to fake a DNS.

Example :

# ./fdns 192.168.1.1
$ nslookup www.google.com 127.0.0.1
Server:        127.0.0.1
Address:    127.0.0.1#53

Non-authoritative answer:
Name:    www.google.com
Address: 192.168.1.1

Another solution worth looking at is dnsmasq. You can easily setup your own local DNS with caching as well as DCHP. The DNS part can be configured to redirect everything to the same IP address with the following parameter:

address=/#/192.168.1.1
This entry was posted in Informatique, Internet. Bookmark the permalink.

5 Responses to Fake DNS in C

  1. Krute Munday says:

    Hello mate, I used your fdns.c as a name server for some of my domains. I want to point those domains to a same ip address like 11.22.33.44 after I directly point my domains’ name servers to this fake name server.

    I setup it and seems it’s working. But have problems. When I use google DNS I can ping out the correct IP address 11.22.33.44 but if I use some other DNS like 4.3.2.1, it told me that the domains are not resolvable.

    Any help?

    Thanks.

  2. lordikc says:

    Hello,

    What dou you mean by ping 4.3.2.1 ? DNS is about name resolution so if you ping an IP it doesn’t use DNS.

    Regards

  3. Krute Munday says:

    No I don’t mean PING 4.3.2.1
    I mean:

    1. I am using this fake dns as a public name server in the internet, for some of my domains. I usually register some domains and setup their name servers and setup their A records to a same IP address in the domain control panel like godaddy. However it’s a heavy work if you have a lot of domains. So I compiled your fdns.c and use it as a name server in my vps like ns1.fakedns.com. I pointed my domains’ name servers to ns1.fakedns.com (for example testdomain.com). Just want if someone visit testdomain.com and the fake dns server ns1.fakedns.com will respone a fixed IP address like 123.123.123.123 to that request.

    2. When visitors’ computer using some DNS services such as google’s public DNS 8.8.8.8, the above domain testdomain.com will be return a valid IP address 123.123.123.123

    3. However if I use some other public DNS service like 4.3.2.1, I can’t get any valid IP address while I visit testdomain.com, seems that ns1.fakedns.com doesn’t work.

    I don’t know why lol. But I need your help. Could you please contact me with email left with this comments? Thanks.

  4. lordikc says:

    Sorry I don’t get it. This fake DNS was a very simple attempt to provide a simple DNS server returning the same IP whatever the request is. So that, for instance, when one tries to browse http://www.google.com, he’s moved to the pre-configured IP. The initial purposed was to create an AP for sharing files without internet connection. In fact dnsmasq does it far better so I dropted it.

  5. wendal says:

    Good job!!
    Thank you a lot!!