** Note: ** DNS does not allow any interruption because it relates to almost all services on the Intranet cluster. You must configure active and standby DNS at the same time to prevent service interruption.

# Use tools

  • dnsmasq
  • Keepalived (optional, configure virtual IP to run the service)

To prepare

If Ubuntu 18.04 comes with systemd-resolve, you need to disable it because it is bound to port 53, which conflicts with Dnsmasq port. Run the following command to disable the resolved service: sudo systemctl stop Systemd-resolved sudo systemctl disable systemd-resolved

The installation

sudo apt-get install dnsmasq

Example Modify the configuration file /etc/dnsmasq.conf

Domain.com is the configured domain name and can be changed as required

Listen - address = 0.0.0.0#domain-needed This tells dnsmasq to never pass short names to the upstream DNS servers. If the name is not in the local /etc/hosts file then “not found” will be returned.
domain-needed

#bogus-priv All reverse IP (192.168.x.x) lookups that are not found in /etc/hosts will be returned as “no such domain” and not forwarded to the upstream servers.
bogus-priv

#no-resolv Do not read resolv.conf to find the servers where to lookup dns.
no-resolv

#Set the size of dnsmasq's cache. The default is 150 names. Setting the cache size to zero disables caching.
#cache-size=500

#no-poll Do not poll resolv.conf for changesNo - poll server=/domain.com/192.168.1.114#server=8.8.8.8 Set one or more DNS servers to use when addresses are not local.Server = 114.114.114.114#local=/example.com/ Our local domain, queries in these domains are answered from /etc/hosts or the static-hosts files.
local=/domain.com/

# address=/doubleclick.net/127.0.0.1 Use this force an address for the specified domains. Um participant to block adverts force doubleclck.net to localhost
# address=/chianyu.com/192.168.1.114

#no-hosts This options stops dnsmasq using the local /etc/hosts file as a source for lookups .
no-hosts

#addn-hosts=/etc/dnsmasq_static_hosts.conf Force dnsmasq to use this file for lookups. It is in the same format as /etc/hosts.
addn-hosts=/etc/dnsmasq_static_hosts.conf
#In the file /etc/dnsmasq_static_hosts.conf you can add a list of local machines with static IP addresses in the same format as the hosts file. It is also an easy way of creating aliases or CNAME records.
#192.168.0.8  mail mail.example.com
#192.168.0.9  smtp smtp.example.com

#expand_hosts So we can see our local hosts via our home domain without having to repeatedly specify the domain in our /etc/hosts file.
expand-hosts

#domain This is your local domain name. It will tell the DHCP server which host to give out IP addresses for.DHCP - range = domain=chianyu.com 192.168.1.100 192.168.1.200, 72 h DHCP - range = TFTP, 192.168.1.230, 192.168.1.239Static binding of DHCP services
# Always set the name and ipaddr of the host with hardware address
# DHCP - host = 00:0 C: yes, E: F2:6 f, 192.168.1.201
# DHCP - host = 00:0 C: yes, E: F2:6 f, 192.168.1.201, infinite infinite lease
# DHCP - host = mylaptop, 192.168.0.199, 36 h Any machine saying they are the hostname = 'mylaptop gets this IP address

Ignore DHCP requests for the following MAC addresses
# Never offer DHCP service to a machine whose ethernet
# address is 11:22:33:44:55:66
#dhcp-host=11:22:33:44:55:66,ignore

# DHCP - option = option: the router, 192.168.1.1 the When a host is requesting an IP address via DHCP also tell it the gateway to use.DHCP - option = option: the router, 192.168.1.1#dhcp-option=option:ntp-server,192.168.1.4 When a host is requesting an IP address via DHCP also tell it the NTP to use.
# DHCP - option = option: the NTP server, 192.168.1.1DHCP - option = 19, 0# ip-forwarding offDHCP - option = 44192168. 1.114# set netbios-over-TCP/IP aka WINSDHCP - option = 45192168. 1.114# netbios datagram distribution serverDHCP - option = 46, 8# netbios node type
Copy the code

Modify the static host configuration file

Modify the file sudo vim /etc/dnsmasq_STATIC_hosts.conf

192.168.1.110    dns1.domain.com       dns1
192.168.1.111    dns2.domain.com       dns2
192.168.1.112    haproxy.domain.com    haproxy
192.168.1.113    mysql.domain.com      mysql
192.168.1.114    myapp.domain.com      myapp
192.168.1.115    router.domain.com     router
Copy the code

** attention: ** must pay attention!! There must be no empty lines between records. Otherwise, the ping of the domain name may pause for several seconds and then respond, or the ping may fail. The reason is unknown, but it may be that DNSMASQ does not parse the file format well enough.

Add boot

Modify /etc/rc.local add service dnsmasq restart

The attached

  • DNSmasq Detailed analysis and configuration
  • Dnsmasq Advanced skills