Is updating /etc/hosts required?

I’ve been learning HAProxy, every tutorial I’ve been looking at seems to edit the /etc/hosts file, but I’m unsure why, is it required?

I’ve got roundrobin working with 2 servers, tho I haven’t set up any actualy domain names to test with. But using the ips i.e going to / works without needing any host file edits.

Is there any documentation which explains this requirement?

The documentation only suggests to use /etc/hosts when using hostnames in ACLs:

IPv4 addresses values can be specified either as plain addresses or with a netmask appended, in which case the IPv4 address matches whenever it is within the network. Plain addresses may also be replaced with a resolvable host name, but this practice is generally discouraged as it makes it more difficult to read and debug configurations. If hostnames are used, you should at least ensure that they are present in /etc/hosts so that the configuration does not depend on any random DNS match at the moment the configuration is parsed.

That’s it.

1 Like

Ah so I’m not doing anything wrong. Thanks alot. I figured the tutorials were trying to simulate the load balancer on their local machine but they weren’t making use of any of the entries in the host file so I couldn’t figure out a valid scenario where it was being used, and literally skipping that step broke nothing.

Also thanks for linking to 2.6 docs, for some reason I’m looking at 2.5rc docs.