It is possible to configure DNSMasq such that it returns a fixed IP address only for a request for that exact domain, and not for its subdomains? That is, I want it to return a fixed IP when resolving example.com
, but not a.example.com
, b.example.com
, etc.
![](../../users/profiles/44689.webp)
- 269
- 3
- 15
4 Answers
host-record=example.com,1.2.3.4
The dnsmasq man page says:
--host-record=<name>[,<name>....][<IPv4-address>],[<IPv6-address>]
Add A, AAAA and PTR records to the DNS. This adds one or more names to the DNS with associated IPv4 (A) and IPv6 (AAAA) records. A name may appear in more than one host-record and therefore be assigned more than one address. Only the first address creates a PTR record linking the address to the name. This is the same rule as is used reading hosts-files. host-record options are considered to be read before host-files, so a name appearing there inhibits PTR-record creation if it appears in hosts-file also. Unlike hosts-files, names are not expanded, even when expand-hosts is in effect. Short and long names may appear in the same host-record, eg. --host-record=laptop,laptop.thekelleys.org,192.168.0.1,1234::100
![](../../users/profiles/126632.webp)
- 237,123
- 42
- 477
- 940
![](../../users/profiles/200407.webp)
- 91
- 1
- 2
-
The question carries the tag "internal-dns", where "host-record" applies to external-dns a.k.a. authoritative dns. – Pro Backup Dec 09 '16 at 21:12
-
note that if you are trying to take over an existing host record on the internet (e.g. rewrite it for your lan), then if you omit the v6 address and the host has a real v6 address on the internet, dnsmasq will return your overridden v4 address as A, and the real internet v6 AAAA record. specify both if you don't want v6-capable hosts to not "fall through" to the real internet host via v6. I was rewriting archive.ubuntu.com to point at my local mirror, and only specified the v4 address on my LAN - turns out it also has a v6 address and I needed to make sure I configured that in dnsmasq too. – sneak Mar 29 '19 at 08:51
How is your configuration file? dnsmasq will resolve only subdomains if your entry starts with dot .
Example: address=/.subdomain.pc01.domain.com/192.168.1.2
If you have it this way:
address=/subdomain.pc01.domain.com/192.168.1.2
it will also resolve asd.subdomain.pc01.domain.com
:
$ host asd.subdomain.pc01.domain.com
asd.subdomain.pc01.domain.com has address 192.168.1.2
![](../../users/profiles/157075.webp)
- 945
- 8
- 13
-
Interesting point, but if your read the question carefully, this isn't what the OP was asking for. – jcharaoui May 30 '16 at 18:38
From the man page of dnsmasq (for --server, but also applies to --address):
More specific domains take precendence over less specific domains, so: --server=/google.com/1.2.3.4 --server=/www.google.com/2.3.4.5 will send queries for *.google.com to 1.2.3.4, except *www.google.com, which will go to 2.3.4.5
So the only solution I can see is to instead add individual records for each of the subdomains necessary. Obviously not ideal, but is the best dnsmasq can provide at this time (that I can find).
![](../../users/profiles/58240.webp)
- 121
- 2
- 7
Just add an entry for that specific domain in the hosts file on the server running DNSMasq
![](../../users/profiles/105072.webp)
- 24,907
- 4
- 62
- 95
-
That doesn't work; DNSMasq returns the same fixed IP for all subdomains of the entered domain – Michael Mrozek Dec 22 '12 at 04:30