2017-09-04 22:44:13 +00:00
---
2020-04-07 18:55:19 +00:00
layout: docs
page_title: Consul Enterprise Network Segments
2017-09-04 22:44:13 +00:00
description: |-
Consul Enterprise enables you create separate LAN gossip pools within one
cluster to segment network groups.
---
2020-03-24 20:06:20 +00:00
# Network Segments
2017-09-04 22:44:13 +00:00
2020-04-23 22:13:18 +00:00
<EnterpriseAlert>
2020-07-08 23:09:00 +00:00
This feature requires{' '}
<a href="https://www.hashicorp.com/products/consul/">Consul Enterprise</a>{' '}
2021-07-27 01:09:03 +00:00
version 0.9.3+ with the Global Visibility, Routing, and Scale module.
2020-04-23 22:13:18 +00:00
</EnterpriseAlert>
2021-07-27 01:09:03 +00:00
Consul requires full connectivity between all agents (servers and clients) in a
2022-01-10 21:13:13 +00:00
[datacenter](/docs/agent/config/agent-config-cli#_datacenter) within a given
2021-07-27 01:09:03 +00:00
LAN gossip pool. By default, all Consul agents will be a part of one shared Serf LAN
gossip pool known as the `<default>` network segment, thus requiring full mesh
connectivity within the datacenter.
2017-09-04 22:44:13 +00:00
2021-07-27 01:09:03 +00:00
![Consul datacenter default agent connectivity: one network segment](/img/network-segments/consul-network-segments-single.png)
2017-09-04 22:44:13 +00:00
2021-07-27 01:09:03 +00:00
In some environments, full connectivity between all agents is not possible—known as a
"segmented network". This is usually the result of business policies enforced through
network rules or firewalls. To use Consul in a segmented network, you must break up
the LAN gossip pool along network communication boundaries into separate "network
segments". Network segments are isolated LAN gossip pools that only require full
connectivity between agent members on the same segment.
![Consul datacenter agent connectivity with network segments](/img/network-segments/consul-network-segments-multiple.png)
To get started with network segments you can review the tutorial on HashiCorp
Learn for [Network Segments](https://learn.hashicorp.com/tutorials/consul/network-partition-datacenters).
-> **Info:** Network segments enable you to operate a Consul datacenter without full
mesh (LAN) connectivity between agents. To federate multiple Consul datacenters
without full mesh (WAN) connectivity between all server agents in all datacenters,
use [Network Areas (Enterprise)](/docs/enterprise/federation).
2020-01-09 09:41:31 +00:00
2017-09-04 22:44:13 +00:00
# Consul Networking Models
To help set context for this feature, it is useful to understand the various
Consul networking models and their capabilities.
**Cluster:** A set of Consul servers forming a Raft quorum along with a
collection of Consul clients, all set to the same
2022-01-10 21:13:13 +00:00
[datacenter](/docs/agent/config/agent-config-cli#_datacenter), and joined together to form
2017-09-04 22:44:13 +00:00
what we will call a "local cluster". Consul clients discover the Consul servers
in their local cluster through the gossip mechanism and make RPC requests to
2020-04-06 20:27:35 +00:00
them. LAN Gossip (OSS) is an open intra-cluster networking model, and Network
2017-09-04 22:44:13 +00:00
Segments (Enterprise) creates multiple segments within one cluster.
**Federated Cluster:** A cluster of clusters with a Consul server group per
cluster each set per "datacenter". These Consul servers are federated together
over the WAN. Consul clients make use of resources in federated clusters by
forwarding RPCs through the Consul servers in their local cluster, but they
never interact with remote Consul servers directly. There are currently two
2020-04-06 20:27:35 +00:00
inter-cluster network models which can be viewed on HashiCorp Learn:
2020-08-13 21:02:44 +00:00
[WAN gossip (OSS)](https://learn.hashicorp.com/tutorials/consul/federarion-gossip-wan)
and [Network Areas (Enterprise)](https://learn.hashicorp.com/tutorials/consul/federation-network-areas).
2017-09-04 22:44:13 +00:00
**LAN Gossip Pool**: A set of Consul agents that have full mesh connectivity
among themselves, and use Serf to maintain a shared view of the members of the
pool for different purposes, like finding a Consul server in a local cluster,
or finding servers in a remote cluster. A **segmented** LAN Gossip Pool limits a
group of agents to only connect with the agents in its segment.
2021-07-27 01:09:03 +00:00
# Network Segments Configuration
## Server Configuration
Server agents are members of all segments. The datacenter includes a `<default>`
segment, as well as additional segments defined in the
2022-01-10 21:13:13 +00:00
[`segments`](/docs/agent/config/agent-config-files#segments) server agent configuration option.
2021-07-27 01:09:03 +00:00
Each additional segment is defined by:
- a non-empty name
- a unique port
- optionally, a custom bind and advertise address for the additional segment's
Serf LAN listener on the server
~> **Note:** Prior to Consul 1.7.3, a Consul server agent configured with too
many network segments may not be able to start due to [limitations](https://learn.hashicorp.com/tutorials/consul/network-partition-datacenters#network-segments-limitations)
in Serf.
### Example Server Configuration
The following server agent configuration will create two user-defined network
segments: `alpha` and `beta`.
<CodeTabs heading="Example network segments configuration for server agents">
```hcl
segments = [
{
name = "alpha"
bind = "{{GetPrivateIP}}"
advertise = "{{GetPrivateIP}}"
port = 8303
},
{
name = "beta"
bind = "{{GetPrivateIP}}"
advertise = "{{GetPrivateIP}}"
port = 8304
}
]
```
```json
{
"segments": [
{
"name": "alpha",
"bind": "{{GetPrivateIP}}",
"advertise": "{{GetPrivateIP}}",
"port": 8303
},
{
"name": "beta",
"bind": "{{GetPrivateIP}}",
"advertise": "{{GetPrivateIP}}",
"port": 8304
}
]
}
```
</CodeTabs>
2022-01-10 21:13:13 +00:00
The server [agent configuration](/docs/agent/config/agent-config-files) options relevant to network
2021-07-27 01:09:03 +00:00
segments are:
2022-01-10 21:13:13 +00:00
- [`ports.serf_lan`](/docs/agent/config/agent-config-files#serf_lan_port): The Serf LAN port on this server
2021-07-27 01:09:03 +00:00
for the `<default>` network segment's gossip pool.
2022-01-10 21:13:13 +00:00
- [`segments`](/docs/agent/config/agent-config-files#segments): A list of user-defined network segments
2021-07-27 01:09:03 +00:00
on this server, including their names and Serf LAN ports.
## Client Configuration
Each client agent can only be a member of one segment at a time. This will be the
`<default>` segment unless otherwise specified in the agent's
2022-01-10 21:13:13 +00:00
[`segment`](/docs/agent/config/agent-config-cli#_segment) agent configuration option.
2021-07-27 01:09:03 +00:00
### Join a Client to a Segment ((#join_a_client_to_a_segment))
For a client agent to [join](/commands/join) the Consul
datacenter, it must connect to another agent (client or server) within its
configured segment.
<Tabs>
<Tab heading="Join via another client">
Clients A and B specify the same segment S. Client B is already joined to the segment S
LAN gossip pool. Client A wants to join via Client B. In order to do so, Client A
2022-01-10 21:13:13 +00:00
must connect to Client B's configured [Serf LAN port](/docs/agent/config/agent-config-files#serf_lan_port).
2021-07-27 01:09:03 +00:00
</Tab>
<Tab heading="Join via a server">
Client A specifies segment S and wants to join the segment S gossip pool via Server 1.
In order to do so, Client A must connect to Server 1's configured [Serf LAN port
2022-01-10 21:13:13 +00:00
for segment S](/docs/agent/config/agent-config-files#segment_port).
2021-07-27 01:09:03 +00:00
</Tab>
</Tabs>
There are several methods to specify the port used by the join operation, listed in order
of precedence:
1. **Specify an explicit port in the join address**. This can be done at the CLI when starting
the agent (e.g., `consul agent -retry-join "client-b-address:8303"`), or in the agent's
2022-01-10 21:13:13 +00:00
configuration using the [retry-join option](/docs/agent/config/agent-config-files#retry_join). This method
2021-07-27 01:09:03 +00:00
is not compatible with [cloud auto-join](/docs/install/cloud-auto-join#auto-join-with-network-segments).
2. **Specify an alternate Serf LAN port for the agent**. This can be done at the CLI when starting
the agent (e.g., `consul agent -retry-join "client-b-address" -serf-lan-port 8303`), or in
2022-01-10 21:13:13 +00:00
the agent's configuration using the [serf_lan](/docs/agent/config/agent-config-files#serf_lan_port) option.
2021-07-27 01:09:03 +00:00
When a Serf LAN port is not explicitly specified in the join address, the agent will attempt to
join the target host at the Serf LAN port specified in CLI or agent configuration.
3. **Use the default Serf LAN port (8301)**. The agent will attempt to join the target host
on port 8301.
-> Agents within a segment can use different port numbers for their Serf LAN port.
For example, on the `<default>` segment, Server S can use port 8301, Client A
can use 8303, and Client B can use 8304. However, if an agent wishes to join a
segment via an agent that uses a different port number, the target agent's Serf LAN
port must be specified in the join address (method 1 above).
### Example Client Configuration
The following client agent configuration will cause the agent to:
- Open a Serf LAN listener port on 8303.
- Attempt to join the cluster via servers on port 8303 (since an alternate port is not
specified in the `retry_join` addresses).
<CodeTabs heading="Example network segment configuration for client agents">
```hcl
node_name = "consul-client1"
retry_join = ["consul-server1", "consul-server2", "consul-server3"]
segment = "alpha"
ports = {
serf_lan = 8303
}
```
```json
{
"node_name": "consul-client1",
"retry_join": ["consul-server1", "consul-server2", "consul-server3"],
"segment": "alpha",
"ports": {
"serf_lan": 8303
}
}
```
</CodeTabs>
2022-01-10 21:13:13 +00:00
The client [agent configuration](/docs/agent/config/agent-config-files) options relevant to network
2021-07-27 01:09:03 +00:00
segments are:
2022-01-10 21:13:13 +00:00
- [`segment`](/docs/agent/config/agent-config-files#segment-2): The name of the network segment this
2021-07-27 01:09:03 +00:00
client agent belongs to.
2022-01-10 21:13:13 +00:00
- [`ports.serf_lan`](/docs/agent/config/agent-config-files#serf_lan_port):
2021-07-27 01:09:03 +00:00
Serf LAN port for the above segment on this client. This is not required
to match the configured Serf LAN port for other agents on this segment.
2022-01-10 21:13:13 +00:00
- [`retry_join`](/docs/agent/config/agent-config-files#retry_join) or
[`start_join`](/docs/agent/config/agent-config-files#start_join): A list of agent addresses to join
2021-07-27 01:09:03 +00:00
when starting. Ensure the correct Serf LAN port for this segment is used when joining
the LAN gossip pool using one of the [available configuration methods](#join_a_client_to_a_segment).