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 – https://imaginea.gitbooks.io/consul-devops-handbook/content/

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 10.0.0.0 – 10.255.255.255 16,777,216 10.0.0.0/8 (255.0.0.0) 24 bits 8 bits single class A network
20-bit block 172.16.0.0 – 172.31.255.255 1,048,576 172.16.0.0/12 (255.240.0.0) 20 bits 12 bits 16 contiguous class B networks
16-bit block 192.168.0.0 – 192.168.255.255 65,536 192.168.0.0/16 (255.255.0.0) 16 bits 16 bits 256 contiguous class C networks

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