Wildcard subdomains with dnsmasq

DnsSubdomainWildcardDnsmasq

Dns Problem Overview


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?

Dns Solutions


Solution 1 - Dns

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

Solution 2 - Dns

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondanbView Question on Stackoverflow
Solution 1 - DnsEkriirkEView Answer on Stackoverflow
Solution 2 - DnsSebastian SchraderView Answer on Stackoverflow