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
?
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
-
4I 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. – Luke A. Leber Nov 7 '15 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 Nov 14 '15 at 14:57
-
6
-
but this can only add one record for a wilcard domain, how can i have multiple record? – Y. King Oct 29 '20 at 7:56
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.
-
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 Jan 16 '17 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 withdig @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. – Sebastian Schrader Feb 1 '17 at 17:22 -
is it possible to do
address=.example/*/foo
? doesn't seem to work for me. – chovy Mar 25 '17 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*
. – Sebastian Schrader Mar 27 '17 at 18:03 -
1Is 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? – CMCDragonkai Jul 13 '17 at 2:14