Hostnames in HAProxy configuration file

Solution 1:

In haproxy >= 1.7, you should be able to use the init-addr option, specifying none to prevent DNS resolution at startup.

From the docs:

init-addr {last | libc | none | <ip>},[...]*

Indicate in what order the server's address should be resolved upon startup if it uses an FQDN. Attempts are made to resolve the address by applying in turn each of the methods mentionned in the comma-delimited list. The first method which succeeds is used. If the end of the list is reached without finding a working method, an error is thrown. Method "last" suggests to pick the address which appears in the state file (see "server-state-file"). Method "libc" uses the libc's internal resolver (gethostbyname() or getaddrinfo() depending on the operating system and build options). Method "none" specifically indicates that the server should start without any valid IP address in a down state. It can be useful to ignore some DNS issues upon startup, waiting for the situation to get fixed later. Finally, an IP address (IPv4 or IPv6) may be provided.

So your config line could be:

server s1 myhostname init-addr none

Solution 2:

No, it is not possible from within haproxy.

According to the manual, the address in the server configuration line is

[...] the IPv4 or IPv6 address of the server. Alternatively, a resolvable hostname is supported [...]

in other words, it is not allowed to use non-resolvable hostnames in the configuration.


Any part of the address string may reference any number of environment variables by preceding their name with a dollar sign ('$') and optionally enclosing them with braces ('{}'), similarly to what is done in Bourne shell.