60

I have a device that is already mapped to domain.tld. I now want to create a wildcard for all subdomains *.domain.tld so that they are mapped to the ip of domain.tld, too. How do I do this with dnsmasq?

2 Answers 2

79

While the accepted answer may have solved the author's problem, it is misleading as it suggests that the leading dot would match subdomains only, which is not true.

dnsmasq ignores any leading dots, so that

address=/domain.tld/192.168.0.1

is equivalent to

address=/.domain.tld/192.168.0.1

or even

address=/......domain.tld/192.168.0.1

As of now (dnsmasq v2.76), there is unfortunately no way to specify some things (server, address, ipset) for

  • a single domain name only, i.e. domain name without its subdomains
  • only for the subdomains of a domain name

The only thing you can do, is to specify something for a domain name and all its subdomain and have override it for specific subdomains, e.g.

address=/domain.tld/192.168.0.1
address=/sub.domain.tld/10.10.0.1

This single domain name only case, may be tackled with different options, such as host-record, srv-record, which may be sufficient in some cases, but certainly not in all. It won't work for example, if you really need to use the server or ipset option for a single domain name only.

11
  • Which version of dnsmasq supports overrides as stated above? I've got dnsmasq 2.76-g0007ee9 from Asus Merlin and it doesn't work
    – Hengjie
    Commented Jan 16, 2017 at 21:32
  • @Hengjie I just tested the overrides in the above example configuration with a build of the official 2.76 release of dnsmasq. I put the two lines in a temporary config file, executed dnsmasq -p 5353 -k -C /tmp/dnsmasq.conf and tested with dig @127.0.0.1 -p 5353 sub.domain.tld. Anyway I don't recall that overriding settings this way has been added in any particular version of dnsmasq. It should basically work with any dnsmasq version. Commented Feb 1, 2017 at 17:22
  • is it possible to do address=.example/*/foo ? doesn't seem to work for me.
    – chovy
    Commented Mar 25, 2017 at 3:55
  • @chovy You should probably ask a separate question. It is unclear, what you intend to do and what doesn't work. Something which I can definitely say is, that the wildcard in the address option is # not *. Commented Mar 27, 2017 at 18:03
  • 1
    Is it possible to do something like address=localhost.*/127.0.0.1? That is point any host with a subdomain of localhost to 127.0.0.1? Commented Jul 13, 2017 at 2:14
75

In the dnsmasq.conf file, add the line

address=/.domain.tld/192.168.0.1

But use the IP you actually want as that end bit

5
  • 7
    I would usually create a separate configuration file for each host and place it in the '/etc/dnsmasq.d/' directory. The advantage to this is not having to deal with such a monolithic file when it comes time for maintenance. Commented Nov 7, 2015 at 22:41
  • 1
    @LukeA.Leber that sound even more tedious as finding the correct host file would be the same or even less "maintainable" as a line in a file. Then on top of locating the file you have to make the same edit(s). More work.
    – EkriirkE
    Commented Nov 14, 2015 at 14:57
  • 8
    See below: a leading dot is not a wildcard Commented Nov 5, 2016 at 18:33
  • but this can only add one record for a wilcard domain, how can i have multiple record?
    – Y. King
    Commented Oct 29, 2020 at 7:56
  • 2
    Wildcards in dnsmasq works out of the box... address=/domain.tld/192.168.0.1 domain.tld and also any subdomain e.g. sub.domain.tld will be translated to 192.168.0.1. So entering dot at the start of misleading. When we add entry address=/another.domain.tld/192.168.0.255 it will be translated to 192.168.0.255 but any not defined subdomain to 192.168.0.1
    – mikep
    Commented Jun 14, 2022 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.