3

I would like to let the DNS works in round robin way. So I have to put an entry into /etc/hosts. However, this does not allow wildcard domains.

Is there any way that I can do this in dnsmasq?

So I will get something like:

*.test.example.              0       IN      CNAME   mytest.example.
mytest.example.              0       IN      A       192.0.2.123

1 Answer 1

5

I've checked v2.77 and found that wildcard CNAME is working there. You should add to config cname=*.example.com,default.example.com, but your dnsmasq should be authoritative server for domain(in this case for example.com). It could be configured according man. In my case, I have such configuration:

/etc/hosts

127.0.0.1       default.example.com
127.0.0.2       default.example.com
127.0.0.3       default.example.com
127.0.0.4       default.example.com
127.0.0.5       default.example.com

/etc/dnsmasq.conf

cname=*.example.com,default.example.com
auth-server=example.com,eth0
interface-name=example.com,eth0
auth-zone=example.com,127.0.0.0/24,eth0

And result:

[root@centos-linux ~]# dig @127.0.0.1 *.example.com

; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.3 <<>> @127.0.0.1 *.example.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6531
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;*.example.com.         IN  A

;; ANSWER SECTION:
*.example.com.      600 IN  CNAME   default.example.com.
default.example.com.    600 IN  A   127.0.0.3
default.example.com.    600 IN  A   127.0.0.4
default.example.com.    600 IN  A   127.0.0.5
default.example.com.    600 IN  A   127.0.0.2
default.example.com.    600 IN  A   127.0.0.1

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Jun 05 16:28:13 MSK 2017
;; MSG SIZE  rcvd: 155

[root@centos-linux ~]# nslookup 2.example.com 127.0.0.1
Server:     127.0.0.1
Address:    127.0.0.1#53

Non-authoritative answer:
2.example.com   canonical name = default.example.com.
Name:   default.example.com
Address: 127.0.0.5
Name:   default.example.com
Address: 127.0.0.2
Name:   default.example.com
Address: 127.0.0.3
Name:   default.example.com
Address: 127.0.0.4
Name:   default.example.com
Address: 127.0.0.1
7
  • I am aware of address= has wildcard. However, address= does not do round robin. It does not allow multiple IPs at all.
    – Wang
    Jun 5, 2017 at 11:21
  • @Wang please check update, I found solution for dnsmasq v2.77 Jun 5, 2017 at 13:29
  • Thanks! WoW, just saw the change log, I am so lucky! Would you please remove the part in your answer before your update? It is apparently irrelevant.
    – Wang
    Jun 5, 2017 at 13:46
  • 7
    This is completely the wrong answer. A DNS record which resolves the literal query ".domain.com" is not a wildcard record. This is a bad DNS record for a single domain called ".domain.com" There seems to be some confusion in the DNSmasq documentation about this, as the author calls this out in his docs. The syntax "address=/domain.com/1.1.1.1" does create a wildcard domain, but only for a single IP. FWIW the wildcard form of the above question should resolve any sub-domain of example.com to the same address(es), but it does not.
    – Stephen
    May 29, 2018 at 21:56
  • 2
    just to clarify the above comment lost to formatting the asterisk as italics, this answer does not create a wildcard, it creates a record for a literal asterisk.example.com *.example.com CNAME to example.com which is not useful at all Jul 1, 2020 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.