Configure Consul multi-datacenter WAN federation for geographic redundancy

Advanced 45 min May 15, 2026 26 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up Consul WAN federation to connect multiple datacenters for global service discovery and failover. This tutorial covers primary and secondary datacenter configuration with ACL token replication and cross-datacenter networking.

Prerequisites

  • Multiple servers across different datacenters
  • Network connectivity between datacenters
  • Basic understanding of Consul architecture
  • Firewall access to configure ports 8300-8502

What this solves

Consul multi-datacenter WAN federation allows you to connect Consul clusters across different geographic locations or network segments. This provides global service discovery, cross-datacenter failover, and centralized configuration management while maintaining local autonomy in each datacenter. You need this when running distributed applications across multiple regions or availability zones.

Multi-datacenter architecture planning

Before configuring WAN federation, plan your datacenter topology. Each datacenter runs an independent Consul cluster with its own servers and agents. The primary datacenter handles ACL tokens and configuration replication, while secondary datacenters federate with the primary for global coordination.

Note: WAN federation requires network connectivity between datacenters on specific ports. Plan your firewall rules and network routing before starting the configuration.

Step-by-step configuration

Install Consul on all nodes

Install Consul on servers in both datacenters. Use the same version across all nodes to ensure compatibility.

wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update
sudo apt install -y consul
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo dnf install -y consul

Generate encryption keys and certificates

Create shared encryption keys and TLS certificates for secure communication between datacenters.

consul keygen
consul tls ca create
consul tls cert create -server -dc dc1
consul tls cert create -server -dc dc2

Save the encryption key output and distribute the CA certificate and keys to all nodes in both datacenters.

Configure primary datacenter (dc1)

Configure the primary datacenter servers with WAN federation enabled. This datacenter will be the authoritative source for ACL tokens.

datacenter = "dc1"
primary_datacenter = "dc1"
data_dir = "/opt/consul"
log_level = "INFO"
server = true
bootstrap_expect = 3
bind_addr = "203.0.113.10"
client_addr = "0.0.0.0"
retry_join = ["203.0.113.11", "203.0.113.12"]

connect {
  enabled = true
}

ports {
  grpc = 8502
}

encrypt = "your-encryption-key-here"

tls {
  defaults {
    ca_file = "/etc/consul.d/tls/consul-agent-ca.pem"
    cert_file = "/etc/consul.d/tls/dc1-server-consul-0.pem"
    key_file = "/etc/consul.d/tls/dc1-server-consul-0-key.pem"
    verify_incoming = true
    verify_outgoing = true
  }
  internal_rpc {
    verify_server_hostname = true
  }
}

acl = {
  enabled = true
  default_policy = "deny"
  enable_token_persistence = true
}

ui_config {
  enabled = true
}

Configure secondary datacenter (dc2)

Configure secondary datacenter servers to federate with the primary datacenter for ACL token replication and global coordination.

datacenter = "dc2"
primary_datacenter = "dc1"
data_dir = "/opt/consul"
log_level = "INFO"
server = true
bootstrap_expect = 3
bind_addr = "198.51.100.10"
client_addr = "0.0.0.0"
retry_join = ["198.51.100.11", "198.51.100.12"]
retry_join_wan = ["203.0.113.10", "203.0.113.11", "203.0.113.12"]

connect {
  enabled = true
}

ports {
  grpc = 8502
}

encrypt = "your-encryption-key-here"

tls {
  defaults {
    ca_file = "/etc/consul.d/tls/consul-agent-ca.pem"
    cert_file = "/etc/consul.d/tls/dc2-server-consul-0.pem"
    key_file = "/etc/consul.d/tls/dc2-server-consul-0-key.pem"
    verify_incoming = true
    verify_outgoing = true
  }
  internal_rpc {
    verify_server_hostname = true
  }
}

acl = {
  enabled = true
  default_policy = "deny"
  enable_token_persistence = true
  enable_token_replication = true
}

ui_config {
  enabled = true
}

Create Consul user and set permissions

Create a dedicated user for Consul and set appropriate file permissions for security.

sudo useradd --system --home /etc/consul.d --shell /bin/false consul
sudo mkdir -p /opt/consul /etc/consul.d/tls
sudo chown -R consul:consul /opt/consul /etc/consul.d
sudo chmod 640 /etc/consul.d/consul.hcl
sudo chmod 640 /etc/consul.d/tls/*
Never use chmod 777. Consul configuration contains sensitive encryption keys and certificates. Use minimal permissions with proper ownership instead.

Configure firewall rules

Open required ports for Consul communication between datacenters. WAN federation uses additional ports for cross-datacenter communication.

sudo ufw allow 8300/tcp comment "Consul server RPC"
sudo ufw allow 8301/tcp comment "Consul serf LAN"
sudo ufw allow 8301/udp comment "Consul serf LAN"
sudo ufw allow 8302/tcp comment "Consul serf WAN"
sudo ufw allow 8302/udp comment "Consul serf WAN"
sudo ufw allow 8500/tcp comment "Consul HTTP API"
sudo ufw allow 8502/tcp comment "Consul gRPC API"
sudo ufw reload
sudo firewall-cmd --permanent --add-port=8300/tcp --add-port=8301/tcp --add-port=8301/udp
sudo firewall-cmd --permanent --add-port=8302/tcp --add-port=8302/udp
sudo firewall-cmd --permanent --add-port=8500/tcp --add-port=8502/tcp
sudo firewall-cmd --reload

Start Consul services

Start Consul on all servers in the primary datacenter first, then start the secondary datacenter nodes.

sudo systemctl enable consul
sudo systemctl start consul
sudo systemctl status consul

Bootstrap ACL system in primary datacenter

Initialize the ACL system in the primary datacenter to generate the bootstrap token for administration.

consul acl bootstrap

Save the SecretID from the output as your master token. Export it for subsequent commands.

export CONSUL_HTTP_TOKEN="your-bootstrap-token-here"

Create replication token

Create an ACL token for cross-datacenter replication with appropriate permissions.

consul acl policy create -name "replication" -rules @- << EOF
acl = "write"
service_prefix "" {
  policy = "read"
  intentions = "read"
}
node_prefix "" {
  policy = "read"
}
EOF
consul acl token create -description "Replication token" -policy-name "replication"

Save the token SecretID for configuring secondary datacenters.

Configure ACL replication on secondary datacenter

Set the replication token on secondary datacenter servers to enable ACL synchronization.

consul acl set-agent-token replication "your-replication-token-here"

Verify WAN federation

Check that datacenters are properly federated and can communicate across the WAN.

consul members -wan
consul catalog datacenters

Cross-datacenter service discovery and monitoring

With WAN federation configured, services can discover and communicate across datacenters. Configure service definitions with datacenter-aware health checks and failover policies.

Register cross-datacenter service

Register a service that can be discovered from multiple datacenters with health checking.

{
  "service": {
    "name": "web",
    "port": 80,
    "check": {
      "http": "http://localhost:80/health",
      "interval": "10s"
    },
    "meta": {
      "datacenter": "dc1"
    }
  }
}
sudo systemctl reload consul

Query services across datacenters

Test cross-datacenter service discovery using the Consul API and DNS interface.

consul catalog services -datacenter dc1
consul catalog services -datacenter dc2
dig @127.0.0.1 -p 8600 web.service.dc1.consul
dig @127.0.0.1 -p 8600 web.service.dc2.consul

Configure prepared queries for failover

Create prepared queries to automatically fail over to other datacenters when local services are unavailable.

consul prepared-query create -name "web-failover" \-service "web" \-failover-datacenters "dc2" \-only-passing

Verify your setup

consul members -wan
consul catalog datacenters
consul acl token list
consul monitor -log-level=DEBUG
dig @127.0.0.1 -p 8600 web-failover.query.consul

The output should show servers from both datacenters in the WAN member list, and cross-datacenter service queries should resolve successfully.

Common issues

Symptom Cause Fix
WAN join fails Firewall blocking port 8302 Open TCP/UDP port 8302 between datacenters
ACL token replication fails Incorrect replication token Verify token has "acl = write" permission
Cross-DC service queries timeout Network connectivity issues Test connectivity on ports 8300-8302 between DCs
TLS handshake failures Certificate hostname mismatch Ensure certificates match server hostnames
Bootstrap token creation fails ACLs already initialized Use existing bootstrap token or reset ACL system

Next steps

Running this in production?

Want this handled for you? Running this at scale adds a second layer of work: capacity planning, failover drills, cost control, and on-call. Our managed platform covers monitoring, backups and 24/7 response by default.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.