2

There's a specific remote subdomain mymachine.home.com whose the IP changes on all the time that I need to update DNSMasq to have it resolve correctly.

But I tested pinging xxxxxx.home.com which doesn't exist and it all seems to want to point to my NginX reverse proxy. (A lot of my entries point there.)

How can I stop DNSMasq from resolving non-existent subdomains to a local IP? (It's always the same IP)

OR

How can I tell DNSMasq to always use external DNS for a specific entry?

This is my installation Configuration.

#DNS_Config
#Dont use external file for custom dns
no-hosts
#Use this file for DNS nameservers (contains googles DNS)
resolv-file=/etc/resolv.dnsmasq.conf

##CUSTOM_DNS
#PING home.com = 192.168.1.210
address=/home.com/192.168.1.210
##DHCP##

##DHCP_Config
#Listen only on eth0
interface=eth0
#DHCP Range 192.168.1.2-127 (12hr lease time)
dhcp-range=192.168.1.2,192.168.1.127,12h
#RESERVE DNSMasq SERVER IP
dhcp-host=00:0c:29:c2:56:bf,192.168.1.149
#Change DEFAULT GATEWAY (Default is same IP as DNSMasq Server)
dhcp-option=option:router,192.168.1.1


##STATIC_DHCP
#STATIC IP to 2 MAC Address that WILL NOT be used simultaneously [IE: Laptop with WiFi + LAN]
dhcp-host=00:00:00:00:00:00,00:00:00:00:00:00,192.168.1.210
#Assign STATIC IP by MAC
dhcp-host=00:00:00:00:00:00,192.168.1.211
5
  • The first question would be the preferred method of resolving this for all subdomains, or answer 2 would require manual intervention for each remote subdomain, but I don't have many remote subdomains, so I'm fine with a work-a-round type fix :P, thanks! Commented Jul 14, 2016 at 0:51
  • I don't understand the question. Which domain do you want to change, and what did you put in the configuration file to make it resolve to a local IP? Post your complete dnsmasq configuration and a precise example of bad resolution: the actual output of dig on the host name (with consistent mungine), and what it should be instead. Commented Jul 14, 2016 at 21:23
  • Its not that complicated, basically, subdomains that do not exist all point to 192.168.1.7, I have a remote subdomain, that if I don't have an entry, it points to 192.168.1.7, but the issue is, the remote IP changes, so I have to update my local DNS entry with the remote IP every time it changes. I want to just remote the entry all together and use Google DNS, but if I remove the entry, it points to 192.168.1.7. .. I posted a link to my entire Configuration, I will post dig later, but I'm at work ATM. Commented Jul 16, 2016 at 14:52
  • You mean that all queries for non-existing domains return 192.168.1.7? I don't think dnsmasq even has a feature to do that. It's something that some ISPs do (to serve ads when you mistype an address). Don't you have the same problem if you query your ISP's servers directly? Are you connecting directly to your ISP or on some internal (e.g. enterprise) network? Also try using 8.8.8.8, 8.8.4.4 (Google) or 208.67.222.222, 208.67.222.220 (OpenDNS) as the upstream DNS provider instead of your ISP's. Commented Jul 16, 2016 at 17:06
  • If you read linked install guide, you would see I forward all requests to Google DNS, also that ISPs have no control over how my internal DNS works, an ISP cant redirect me to 192.168.1.7, and Its not a feature I want, its more of a glitch im trying to resolve, hence the question in the first place. (This is all on my home network), I will try re-installing DNSmasq but i may need a more powerfull DNS program after all. Commented Jul 17, 2016 at 17:52

3 Answers 3

3

The most common reason why you get a bogus IP address for a nonexistent domain is that your ISP converts negative answers into the address of their ad servers, to serve you more ads when you make a typo in the address of a website. This is definitely a shady practice, but unfortunately some ISPs do it.

You can commonly counter that by using different upstream DNS servers, such as OpenDNS (server=208.67.222.222 and server=208.67.220.220) or Google (server=8.8.8.8 and server=8.8.4.4). If you need your ISP's servers for their own customer services, you can use them only in a specific domain (server=/myisp.com/203.0.113.1).

This being said, in your case, the problem is that your configuration doesn't do what you want it to do.

How can I stop DNSMasq from resolving non-existent subdomains to a local IP.

By not declaring the domain to be existing. Dnsmasq does not substitute an IP address for non-existent domains.

How can I tell DNSMasq to always use external DNS for a specific entry.

By not declaring a value for that host name, or a wildcard that encompasses that host name.

The problem in your configuration is the line

address=/home.com/192.168.1.210

This is a wildcard: it declares that 192.168.1.210 is the address of home.com and all host names under that domain. You don't want this wildcard, so remove it.

Instead, declare home.com and any individual domain of home.com as host names, not as wildcards, by listing them in /etc/hosts. Remove the no-hosts line — you want to declare specific hosts, so you need it! Or, if you prefer not to use /etc/hosts, keep this line and add a line pointing to a different file declared with addn-hosts=/path/to/hosts-file. Or, if you want to keep it all inside dnsmasq.conf, replace that line by host-record=home.com,192.168.1.210

If you want to have a wildcard with exceptions (return 192.168.1.210 for all xxx.home.com except for mymachine.home.com, or always query the upstream servers and substitute 192.168.1.210 only for negative answers), I don't think dnsmasq can do this.

1

Just to Expand on Gilles correct Answer :

From TheKelleys.org DNSMasq Man-Page

-A, --address=/<domain>/[domain/][<ipaddr>]

Specify an IP address to return for any host in the given domains. Queries in the domains are never forwarded and always replied to with the specified IP address which may be IPv4 or IPv6. To give both IPv4 and IPv6 addresses for a domain, use repeated -A flags. Note that /etc/hosts and DHCP leases override this for individual names. A common use of this is to redirect the entire doubleclick.net domain to some friendly local web server to avoid banner ads. The domain specification works in the same was as for --server, with the additional facility that /#/ matches any domain. Thus --address=/#/1.2.3.4 will always return 1.2.3.4 for any query not answered from /etc/hosts or DHCP and not sent to an upstream nameserver by a more specific --server directive. As for --server, one or more domains with no address returns a no-such-domain answer, so --address=/example.com/ is equivalent to --server=/example.com/ and returns NXDOMAIN for example.com and all its subdomains.

--host-record=<name>[,<name>....],[<IPv4-address>],[<IPv6-address>][,<TTL>]

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 If the time-to-live is given, it overrides the default, which is zero or the value of --local-ttl. The value is a positive integer and gives the time-to-live in seconds.

0

I had an entry for my domain that was

address=/domain.com/192.168.1.7 (my NginX reverse Proxy)

It was causing all non-existent subdomains like acoimasdin.domain.com to resolve to 192.169.1.7.

Since I already have everything set up to forward domain.com to www.domain.com in apache, I made the entry

address=/www.domain.com/192.168.1.7

Now my remote sub-domain DNS gets forwarded on to Google DNS as it should, and non-existent DNS come back as "host doesn't exist" which is exactly what I wanted!

In essence, I can't have a bottom/top (not sure the correct term) level entry that is domain.com or all non-existent DNS entries will use that DNS entry.

2
  • Oh, I see. You're getting this address only for subdomains of domain.com. You should have mentioned this in your question, it's an important point! But why are you using address if that's not what you mean? address specifies wildcard for the given domain. If you want an address only for the specific host domain.com, then address is not the right option. Write it in a host file. Commented Jul 17, 2016 at 19:47
  • Your question was most definitely not clearly worded. And we expect questions to be self-contained. Always include all relevant information in the question. Don't expect us to go read your blog. Commented Jul 17, 2016 at 20:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .