Dnsmasq

是否可以將萬用字元 CNAME 添加到 dnsmasq 中?

  • August 10, 2018

我想讓 DNS 以循環方式工作。所以我必須在/etc/hosts. 但是,這不允許萬用字元域。

有什麼辦法可以在 dnsmasq 中做到這一點?

所以我會得到類似的東西:

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

我檢查了 v2.77 並發現萬用字元 CNAME 在那里工作。您應該添加到 config cname=*.example.com,default.example.com,但您的 dnsmasq 應該是域的權威伺服器(在本例中為 example.com)。可以根據man配置。就我而言,我有這樣的配置:

/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

結果:

[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

引用自:https://serverfault.com/questions/853282