In this post we will look briefly about Consul Deployment in Single IP and Multiple IP’s Scenarios. This is summarized from a Consul DevOps handbook that I am contributing to –

For running Consul we should have at least one network adapter besides the loop-back interface. Consul prefers private IP addresses (as defined in RFC 1918) for communication by default for security reasons.

If your machine has only a loop-back interface, Consul will start but it will not be a part of any cluster.

Based on the available network adapters and the type of network (public/private) that they are connected to, Consul behavior will vary and the appropriate configuration in each case is different.

A summary of Consul’s behavior in these situations follows

  • Consul prefers private IP addresses by default, if there is only one, no configuration is required.
  • In the case of multiple private IP addresses, Consul won’t start as it does not choose any of them by itself, and specific configuration is required.
  • In case the machine has public IP addresses only, specific configuration is required.
  • The relevant configuration parameters are bind_addr and advertise_addr.

We describe the different scenarios briefly below.

Single IP

Private IP: (It is straight forward however we should know some basics). 

Consul will start and run without any problem. By default, Consul will use the first available private (RFC 1918) IPv4 address.

Public IP: Non-RFC-1918 IP addresses are popularly called as “Public IP address”.

Consul will not start and quit with an error:

Consul does not bind or advertise to a public IP for security reasons, until we provide the bind or advertise keys to override its behavior and force it to bind to a public address.

Multiple IPs

One Private and one or more public IPs

Consul will start and run without any problem. Since we have one private IP, Consul will determine the available private IP and start without any problem. It’s not mandatory to use the private one in this case, if required we can force and bind to a public IP as well.

Multiple Private IPs or Multiple Public IPs

Consul will not start. We need to supply advertise address in our Consul configuration. Consul is unable to choose one IP in this case.

The error in case of multiple private IPs will look like:

We need to specify which IP to use by providing bind or advertise.

In case of multiple public IPs, the error will look like:

As per the requirement we need to force it use the specific IP by providing bind or advertise keys to override its behavior.

A Note on RFC 1918 – The Internet Engineering Task Force (IETF) has directed the Internet Assigned Numbers Authority (IANA) to reserve the following IPv4 address ranges for private networks, as published in RFC 1918:

RFC1918 name IP address range number of addresses largest CIDR block (subnet mask) host id size mask bits classful description[Note 1]
24-bit block – 16,777,216 ( 24 bits 8 bits single class A network
20-bit block – 1,048,576 ( 20 bits 12 bits 16 contiguous class B networks
16-bit block – 65,536 ( 16 bits 16 bits 256 contiguous class C networks

I will be covering more about Consul’s architecture and configurations in future posts.