1. As we've seen in introduction, name resolution in HAProxy occurs at two
    2. different steps of the process life:
    3.  
    4. 1. when starting up, HAProxy parses the server line definition and matches a
    5. host name. It uses libc functions to get the host name resolved. This
    6. resolution relies on /etc/resolv.conf file.
    7.  
    8. 2. at run time, HAProxy performs periodically name resolutions for servers
    9. requiring DNS resolutions.
    10.  
    11. A few other events can trigger a name resolution at run time:
    12. - when a server's health check ends up in a connection timeout: this may be
    13. because the server has a new IP address. So we need to trigger a name
    14. resolution to know this new IP.
    15.  
    16. When using resolvers, the server name can either be a hostname, or a SRV label.
    17. HAProxy considers anything that starts with an underscore as a SRV label. If a
    18. SRV label is specified, then the corresponding SRV records will be retrieved
    19. from the DNS server, and the provided hostnames will be used. The SRV label
    20. will be checked periodically, and if any server are added or removed, haproxy
    21. will automatically do the same.
    22.  
    23. A few things important to notice:
    24. - all the name servers are queried in the meantime. HAProxy will process the
    25. first valid response.
    26.  
    27. - a resolution is considered as invalid (NX, timeout, refused), when all the
    28. servers return an error.

    5.3.2. The resolvers section

    1. This section is dedicated to host information related to name resolution in
    2. HAProxy. There can be as many as resolvers section as needed. Each section can
    3. contain many name servers.
    4.  
    5. When multiple name servers are configured in a resolvers section, then HAProxy
    6. uses the first valid response. In case of invalid responses, only the last one
    7. is treated. Purpose is to give the chance to a slow server to deliver a valid
    8. answer after a fast faulty or outdated server.
    9. When each server returns a different error type, then only the last error is
    10. used by HAProxy. The following processing is applied on this error:
    11.  
    12. 1. HAProxy retries the same DNS query with a new query type. The A queries are
    13. switch to AAAA or the opposite. SRV queries are not concerned here. Timeout
    14. errors are also excluded.
    15.  
    16. 2. When the fallback on the query type was done (or not applicable), HAProxy
    17. retries the original DNS query, with the preferred query type.
    18.  
    19. 3. HAProxy retries previous steps <resolve_retires> times. If no valid
    20. response is received after that, it stops the DNS resolution and reports
    21. the error.
    22.  
    23. For example, with 2 name servers configured in a resolvers section, the
    24. following scenarios are possible:
    25.  
    26. - First response is valid and is applied directly, second response is
    27. ignored
    28.  
    29. - First response is invalid and second one is valid, then second response is
    30. applied
    31.  
    32. - First response is a NX domain and second one a truncated response, then
    33. HAProxy retries the query with a new type
    34.  
    35. - First response is a NX domain and second one is a timeout, then HAProxy
    36. retries the query with a new type
    37.  
    38. - Query timed out for both name servers, then HAProxy retries it with the
    39. same query type
    40.  
    41. As a DNS server may not answer all the IPs in one DNS request, haproxy keeps
    42. a cache of previous answers, an answer will be considered obsolete after
    43. <hold obsolete> seconds without the IP returned.

    1. Defines the maximum payload size accepted by HAProxy and announced to all the
    2. name servers configured in this resolvers section.
    3. <nb> is in bytes. If not set, HAProxy announces 512. (minimal value defined
    4.  
    5. Note: the maximum allowed value is 8192.
    1. DNS server description:
    2. <id> : label of the server, should be unique
    3. <ip> : IP address of the server
    4. <port> : port where the DNS service actually runs

    parse-resolv-conf

    1. Defines <period> during which the last name resolution should be kept based
    2. on last resolution <status>
    3. <status> : last name resolution status. Acceptable values are "nx",
    4. "other", "refused", "", "valid", "obsolete".
    5. <period> : interval between two successive name resolution when the last
    6. answer was in <status>. It follows the HAProxy time format.
    7. <period> is in milliseconds by default.
    8.  
    9. Default value is 10s for "valid", 0s for "obsolete" and 30s for others.

    1. Defines the number <nb> of queries to send to resolve a server name before
    2. giving up.
    3. Default value: 3
    4.  
    5. A retry occurs on name server timeout or when the full sequence of DNS query
    6. type failover is over and we need to start up from the default ANY query
    7. type.

    Example:

    1. nameserver dns1 10.0.0.1:53
    2. nameserver dns2 10.0.0.2:53
    3. parse-resolv-conf
    4. timeout resolve 1s
    5. timeout retry 1s
    6. hold other 30s
    7. hold nx 30s
    8. hold timeout 30s
    9. hold valid 10s