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
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 –
Amphistylar 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.
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. –
Staysail address=.example/*/foo
? doesn't seem to work for me. –
Satinwood #
not *
. –
Staysail address=localhost.*/127.0.0.1
? That is point any host with a subdomain of localhost to 127.0.0.1? –
Froghopper sub2.sub.domain.tld
resolve to? –
Anniceannie #
is a special value handled by dnsmasq, that matches any domain, it can't be used as a wildcard for parts of a domain. –
Staysail dnsmasq-hosts
file and instruct dnsmasq
to use this file with arg -H
. -H, --addn-hosts=<file> Additional hosts file. Read the specified file as well as /etc/hosts. If --no-hosts is given, read only the specified file. This option may be repeated for more than one additional hosts file. If a directory is given, then read all the files contained in that directory. –
Bjork 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. 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 –
Amphistylar 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
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 –
Amphistylar © 2022 - 2024 — McMap. All rights reserved.