13

I would like to configure a nameserver that will return the same IP address ("A" record) for any arbitrary host name. For example:

  • example.com
  • subdomain.example.com
  • someotherdomain.com
  • anyotherdomain.co.uk

should all return the same IP address. Is there a way to do this with BIND? Or is there an alternative to BIND that can do this?

gWaldo
  • 11,887
  • 8
  • 41
  • 68
balexand
  • 233
  • 1
  • 2
  • 6

4 Answers4

22

With BIND, you need a fake root zone to do this. In named.conf, put the following:

zone "." {
    type master;
    file "/etc/bind/db.fakeroot";
};

Then, in that db.fakeroot file, you will need something like the following:

@ IN SOA ns.domain.com. hostmaster.domain.com. ( 1 3h 1h 1w 1d )
  IN NS <ip>
* IN A <ip>

With that configuration, BIND will return the same IP address for all A queries.

Oliver
  • 5,883
  • 23
  • 32
  • Works fine, but the main domain doesn't get resolved ? Any ideeas ? eg : testdomain.com – opc0de Jan 07 '14 at 20:59
  • This works pretty darned well. The only issue is NS record queries for the domain might explode - namely that it serves the NS records for the `.` zone, which won't respond for any given domain's NS queries. (But it otherwise works to serve the proper A record) – Thomas Ward Oct 03 '17 at 18:18
  • any way for microsoft DNS server? – Hassan Faghihi Dec 24 '19 at 18:17
9

According to the dnsmasq man page

address=/#/1.2.3.4

should do the trick.

Gerald Combs
  • 6,331
  • 23
  • 35
  • Thanks! That was so simple. Dnsmasq is definitely easier to configure than BIND. – balexand Jun 08 '12 at 16:09
  • Do you know if there's also a way to use a wildcard with MX records in dnsmasq? – balexand Jun 14 '12 at 18:15
  • It looks like `mx-host` and `mx-target` will do this. – Gerald Combs Jun 14 '12 at 18:49
  • 1
    Do you know how? The use of wildcards with `mx-host` and `mx-target` is not documented in the man page and I can't get it to work. I've tried using similar notation to the `address` option(`#` sign). I've been able to get wildcards working with both `A` and `MX` using BIND using Oliver's suggestion, but I'd actually prefer to use dnsmasq. Thanks! – balexand Jun 15 '12 at 22:55
  • dnsmasq is more of a recursive nameserver than an authoritative one (could be used parly like that, but clearly not its main goal) – Patrick Mevzek Aug 09 '18 at 20:46
  • This answer was absolutely perfect for my use case :) – Ceisc Sep 28 '20 at 08:36
1

You can do wildcard matching in bind.

*.example.com.        IN      A       192.0.2.45

This has to be defined in your named configuration file for the domain. Just be carefull if you need to define other A records for the domain.

Patrick Mevzek
  • 9,273
  • 7
  • 29
  • 42
Francois Wolmarans
  • 1,570
  • 10
  • 14
1

You can also use the tool fakedns. The usage is very simple - it will bind to post 53 UDP and serve the same IP to all A queries. You provide the IP address as a command line parameter. By far the easiest solution. Requires Python to run.

Konrad Gajewski
  • 1,498
  • 3
  • 15
  • 29