I want to configure haproxy to bind to a tcp
as well as tcp6
socket on all interfaces (i.e., 0.0.0.0:80
and :::80
).
I was able to reach this goal with the following settings:
listen web
bind :80 v4v6
bind :::80 v6only
Is there any shorter way than this?
While I expect it to behave different, the v4v6
keyword makes haproxy bind to a v4 socket only.
Best Answer
To listen on the same port for IPv6 and IPv4, use this:
Admittedly, this was an intuitive guess that appears to have been correct... but rather than just post a "lucky" guess as the answer, even though it works, it seems like I should justify it.
My first intuition was that it's not
v4v6
but rather the use of:80
(or, more precisely, the use of no IP address at all, just a port number) that causes this socket to listen on IPv4 only.This seems to be confirmed in the docs for
bind
:So the following three forms are all equivalent, and are all interpreted as being IPv4 by HAProxy:
Next, there is one sentence in the docs for
v4v6
could be read in isolation to indicate thatv4v6
might be usable to extend one of the above bind statements to listen on IPv6......hmmm, but I suspect that this actually means "the v6 default address" (
::
)......and now, I suspect it even more...
So, it appears that
v4v6
only modifiesbind
directives that specify the IPv6 default listen address, which is::
(the 3rd:
is the separator between the address and the port), and is ignored for others.