From 1a87a9ef51fb9a1e359a962f0ed42427b403df6b Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Wed, 10 May 2017 09:30:19 +0200 Subject: [PATCH] agent: use bind address as src unless INADDR_ANY Use the bind address as source address for outgoing RPC connections unless it is INADDR_ANY. The current code uses the advertise address which will not work in certain environments where the advertise address is not routable in the network of the agent, e.g. NAT environment, container... After all, that is the purpose of the advertise address. See #2822 --- command/agent/agent.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index ba15e3851a..965b0316d7 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -440,9 +440,10 @@ func (a *Agent) consulConfig() (*consul.Config, error) { } // set the src address for outgoing rpc connections - // to RPCAdvertise with port 0 so that outgoing - // connections use a random port. - base.RPCSrcAddr = &net.TCPAddr{IP: base.RPCAdvertise.IP} + // Use port 0 so that outgoing connections use a random port. + if !isAddrANY(base.RPCAddr.IP) { + base.RPCSrcAddr = &net.TCPAddr{IP: base.RPCAddr.IP} + } // Format the build string revision := a.config.Revision