Create Network Segments
This topic describes how to create Consul network segments so that services can connect to other services in the LAN gossip pool that have been placed into separate communication boundaries. Refer to Network Segments Overview for additional information.
Requirements
- Consul Enterprise 0.9.3+
Define segments in the server configuration
Add the
segments
block to your server configuration. Refer to thesegments
documentation for details about how to define the configuration.In the following example, an
alpha
segment is configured to listen for traffic on port8303
and abeta
segment is configured to listen to traffic on port8304
:Example network segments configuration for server agentsStart the server using the
consul agent
command. Copy the address for each segment listener so that you can direct clients to join the segment when you start them:Verify that the server is a member of all segments:
Configure clients to join segments
Client agents can only be members of one segment at a time. You can direct clients to join a segment by specifying the address and name of the segment with the -join
and -segment
command line flags when starting the agent.
Alternatively, you can add the retry_join
and segment
parameters to your client agent configuration file:
Verify segments
You can use the CLI, API, or GUI to verify which segments your agents have joined.
Run the consul members
command to verify that the client agents are joined to the correct segments:
You can also pass the name of a segment in the -segment
flag to view agents in a specific segment. Note that server agents display their LAN listener port for the specified segment the segment filter applied. In the following example, the command returns port 8303
for alpha, rather than for the <default>
segment port:
Refer to the members
documentation for additional information.
Related resources
You can also create and run a prepared query to query for additional information about the services registered to client nodes. Prepared queries are HTTP API endpoint features that enable you to run complex queries of Consul nodes. Refer Prepared Query HTTP Endpoint for usage.