vim /etc/dnsmasq.conf # Listen on this specific port instead of the standard DNS port # (53). Setting this to zero completely disables DNS function, # leaving only DHCP and/or TFTP. port=53 # Never forward plain names (without a dot or domain part) domain-needed # Never forward addresses in the non-routed address spaces. bogus-priv # By default, dnsmasq will send queries to any of the upstream # servers it knows about and tries to favour servers to are known # to be up. Uncommenting this forces dnsmasq to try each query # with each server strictly in the order they appear in # /etc/resolv.conf strict-order # Set this (and domain: see below) if you want to have a domain # automatically added to simple names in a hosts-file. expand-hosts # Set the domain for dnsmasq. this is optional, but if it is set, it # does the following things. # 1) Allows DHCP hosts to have fully qualified domain names, as long # as the domain part matches this setting. # 2) Sets the "domain" DHCP option thereby potentially setting the # domain of all systems configured by DHCP # 3) Provides the domain part for"expand-hosts" #domain=thekelleys.org.uk 这里的是主域名,方便在 /etc/hosts 配置的时候,只写前缀即可 domain=feiyang.com # Set Liste address listen-address=127.0.0.1,192.168.17.5 # Set to Server IP for network responses
Adding DNS records
因为我们没有修改 resolv-file, 默认的就是 /etc/hosts
1 2 3 4 5 6 7 8 9 10 11 12
root@ubuntu20:/home/feiyang# cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 ubuntu20 192.168.17.3 gitlab.feiyang.com 233.233.233.233 haha #因为有expand-hosts, 这里是 haha.feiyang.com 1.1.1.1 free.dns.com # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
重启 dnsmasq
1
systemctl restart dnsmasq
test
Ubuntu 20 为 DNS 服务器, 用 Ubuntu18 和 centos7 来进行测试,结果如下