CGNAT Configuration Guide
此内容尚不支持你的语言。
Introduction
Section titled “Introduction”IPv4 address exhaustion remains a critical constraint for Internet Service Providers (ISPs) while IPv4-based services continue to thrive. Carrier-Grade NAT (CGNAT), also known as Large-Scale NAT (LSN) or NAT444, is an operator-grade NAT44 technology that allows a large number of subscribers to share a small pool of public IPv4 addresses, significantly extending the lifespan of the IPv4 infrastructure. The standard behavior and requirements of CGNAT are defined in RFC 6888.
Compared with an ordinary NAT (such as a home router or enterprise egress NAT), CGNAT is not merely a matter of larger scale. It must meet additional carrier-grade requirements:
- Massive numbers of concurrent subscribers and concurrent sessions.
- High multiplexing ratio of public IPv4 addresses.
- Subscriber traceability for law enforcement and audit.
- Log volume control: per-session logging is impractical at carrier scale, so CGNAT assigns each subscriber a port block on a shared public IP address and logs only block allocation/release events.
- Deterministic port resource allocation policies and per-user resource limits.
- High availability and fast failover.
CGNAT is typically deployed on the path: subscriber CPE with a private address (or the shared address space 100.64.0.0/10 per RFC 6598) -> operator CGNAT device -> public IPv4 Internet.
Definitions
Section titled “Definitions”-
CGNAT (Carrier-Grade NAT): An operator-grade IPv4 address and port translation function that allows multiple subscribers to share public IPv4 addresses.
-
NAPT (Network Address Port Translation): The translation method used by CGNAT, in which both the IP address and the transport-layer port number are translated. A unique public IP:port combination identifies each subscriber flow.
-
Port Block Allocation (PBA): The port resource management mechanism of CGNAT. The port range of each public IP address is divided into fixed-size port blocks, and blocks (rather than individual ports) are allocated to subscribers.
-
Port Block: A contiguous set of ports on one public IP address. A block is allocated to a subscriber as a whole, and ports within the block are used by that subscriber’s sessions.
-
Port Allocation Profile: The configurable policy that defines how port blocks are managed: block size, block allocation mode (on-demand/pre-alloc), port selection mode (random/sequence), reserved port range and block cooling time.
-
Address Pool: A set of public IPv4 addresses used for dynamic port block allocation, together with the port allocation profile applied to it.
-
Instance: The CGNAT service entity. An instance binds address pools, references ACLs for traffic diversion, and owns all per-instance policies such as filtering mode, user limits, aging timers and logging.
-
User: A subscriber identified by its inside (private) source IP address. Per RFC 6888 (Paired Pooling, REQ-2), all sessions of one user are mapped to the same public IP address.
-
Session: A translation entry identified by the five-tuple (protocol, inside IP/port, public IP/port, remote IP/port). Sessions are created within the port resources owned by the user.
-
Filtering Mode: The inbound (out2in) admission policy of an existing mapping: EIF (endpoint-independent), ADF (address-dependent) or APDF (address-and-port-dependent).
-
Hairpinning: The capability that allows two subscribers behind the same CGNAT instance to communicate with each other through their public mapping addresses.
-
Static Mapping: A manually configured, fixed translation between an inside endpoint and an outside endpoint. Address-level static mapping keeps the port unchanged; port-level static mapping fixes both the address and the port.
-
Deterministic NAT: A CGNAT mode in which the mapping between an inside address and its public IP + port block is derived from a fixed algorithm (the inside/outside address ratio), allowing the mapping to be reverse-derived without maintaining runtime binding state.
-
Traceability Log: Logs recording port block allocation/release (port-block mode) or session creation/deletion (session mode), exported via syslog or IPFIX.
Architecture Overview
Section titled “Architecture Overview”In a typical CGNAT deployment, subscriber traffic reaches the inside interfaces of the CGNAT device, and the device translates the source address/port to a public address/port from the bound address pool before forwarding towards the public network on the outside interfaces. Return traffic is translated back by matching the session table.

Example: a subscriber packet with source 100.70.11.251:1234 destined to 8.8.8.8 is translated to source 23.159.240.10:2048 and forwarded to the public network; the return traffic is translated back to 100.70.11.251:1234.
Traffic Diversion by ACL
Section titled “Traffic Diversion by ACL”ACL-based diversion decides which subscriber traffic enters the CGNAT translation pipeline. The ACL only describes the traffic matching conditions (source/destination address, protocol, ports); it does not perform translation itself:
- Inside (in2out) direction: traffic matching the permit rules of the ACL bound to a CGNAT instance (via cgnat binding) is diverted into the CGNAT translation pipeline and uses the address pools bound to that instance for port block mapping and translation; traffic not matching any binding follows normal Layer-3 forwarding.
- Outside (out2in) direction: all traffic arriving on outside interfaces is looked up in the session table. On a hit, the destination address/port are translated back to the subscriber; on a miss, the packet is never dropped but forwarded transparently, so non-CGNAT traffic (traffic destined to the device’s own addresses, pass-through services) is unaffected.
Key Concepts
Section titled “Key Concepts”Port Block Allocation
Section titled “Port Block Allocation”The port range of every public IP address in an address pool is divided into port blocks. Each block has exactly one of three states:
| Block State | Meaning |
|---|---|
| FREE | Owned by no user; available for dynamic allocation |
| ALLOCATED | Allocated to a user; dynamic sessions are using its ports |
| COOLING | Released but still in the cooling period; cannot be re-allocated until the cooling time expires, preventing residual packets of the old user from being forwarded to a new user |
Key policy knobs (defined by the port allocation profile):
- Block size: the number of ports per block (default 2048).
- Block allocation mode: on-demand (allocate a block only when the user actually needs ports, default) or pre-alloc (pre-allocate a fixed number of blocks per user).
- Port selection mode: random (default) or sequence within a block.
- Reserved ports: the leading port range excluded from block division (default 0-1023, the end value must be 2^n - 1).
- Cooling time: how long a released block stays in COOLING state (default 120 seconds).
Per RFC 6888 Paired Pooling, once a user is bound to a public IP address, all subsequent blocks of that user are allocated from the same public IP. The public IP selection strategy balances users across IPs: IPs with block occupancy below 80% are preferred, choosing among them the one with the fewest bound users; when all IPs reach 80% occupancy, the IP with the lowest block occupancy is used, and new allocations are best-effort.
User Management
Section titled “User Management”A user is identified by its inside source IP address. Per-user resource limits can be configured on the instance to prevent individual subscribers from exhausting shared resources:
- Maximum number of port blocks per user (1-256).
- Maximum number of ports per user (1-65535).
- Maximum number of concurrent sessions per user (1-10240; unlimited if not configured).
- Maximum session creation rate per user, in sessions per second over a rolling 1-second cycle (1-10240).
All blocks of a user are released and recycled when they have been idle for the configured timeout.
Session Management
Section titled “Session Management”A session (mapping + session entry) is identified by the full five-tuple. Sessions are classified as dynamic sessions (created from PBA port resources; ports are released on deletion) or static sessions (created from a static mapping). Session aging follows TCP state and protocol type, with active refresh on traffic:
| Session State | Default Aging Time | Description |
|---|---|---|
| TCP SYN-SENT / SYN-RCVD | 75 s | |
| TCP ESTABLISHED | 7440 s | |
| TCP FIN-RST (connection closed) | 60 s | |
| UDP ACTIVE | 300 s | |
| ICMP Query | 60 s | |
| Other (stateless protocols) | 60 s |
All aging timers are configurable per instance. In addition, TCP MSS clamping can be configured to avoid IP fragmentation when the path MTU decreases.
Filtering Behavior
Section titled “Filtering Behavior”The filtering mode controls whether packets from external hosts are admitted through an existing mapping (out2in direction):
| Filtering Mode | Behavior |
|---|---|
| EIF (Endpoint-Independent Filtering, default) | As long as the mapping exists, any external host can send packets to the public IP:port (full-cone behavior). Maximizes P2P application compatibility |
| ADF (Address-Dependent Filtering) | Only packets from an external IP address that the user has already communicated with are allowed |
| APDF (Address-Port-Dependent Filtering) | Only packets from the external IP address and port that the user has already communicated with are allowed |
Hairpinning
Section titled “Hairpinning”With hairpinning enabled, two subscribers behind the same CGNAT instance can access each other through the peer’s public mapping address: the device translates both the destination (to the peer’s inside address) and the source (to the local public mapping) of the hairpinned packet.
Static Port Mapping
Section titled “Static Port Mapping”Static mappings provide fixed, predictable translations for servers or special subscribers inside the CGNAT domain. The public addresses used by static mappings belong to a static address pool, which is strictly isolated from the dynamic CGNAT address pool, so static and dynamic usage never contend for the same public IP:
- Address-level static mapping (outside_ip <-> inside_ip, port unchanged): does not create mappings for all 65535 ports. The rule is stored in a static address table, and an exact mapping is created lazily only when traffic actually hits a specific port.
- Port-level static mapping (outside_ip:outside_port <-> inside_ip:inside_port): the mapping is created immediately upon configuration.
Conflict checks at creation time: the outside address must not overlap with any dynamic address pool of the instance; the same public endpoint (outside_ip + protocol, or outside_ip + outside_port + protocol) and the same inside endpoint cannot be duplicated; address-level and port-level rules of the same protocol on the same IP are mutually exclusive; a static mapping cannot cover an existing dynamic mapping with the same inside endpoint.
Deterministic NAT
Section titled “Deterministic NAT”In deterministic mode, the mapping of each inside address to a public IP address + port block is computed from a fixed algorithm: with the inside address count and the outside (pool) address count, the sharing ratio and the per-user port range (ports_per_host = 64512 / sharing_ratio) are derived, so any inside address maps to a fixed, predictable public endpoint. This allows an external system to reverse-derive the private address from a public IP:port and a timestamp without querying the device, which is ideal for traceability-centric deployments, and it reduces traceability logs to almost zero.
Traceability Logging
Section titled “Traceability Logging”Two log modes are supported per instance:
- Port-block log (default, recommended): logs are generated only when a port block is allocated or released. The log volume is about 1/1000 of session-level logging.
- Session-level log: one log per mapping/session creation and deletion, for fine-grained audit.
Logs contain at least: protocol, private source IP/port, public source IP/port (or port block range), remote IP/port, timestamp (millisecond-grade) and VRF identification. Logs can be exported via syslog (up to 8 servers) or IPFIX.
CGNAT Configuration
Section titled “CGNAT Configuration”Enable CGNAT Globally
Section titled “Enable CGNAT Globally”| Operation | Command | Description |
| Enter the system configuration view | configure terminal | - |
| Enable CGNAT globally | cgnat enable |
Configure a Port Allocation Profile
Section titled “Configure a Port Allocation Profile”| Operation | Command | Description |
| Enter the system configuration view | configure terminal | - |
| Create a port allocation profile | cgnat port-allocation-profile profile_name | Enter the port-allocation-profile view |
| Configure the block size | block-size block_size | Default 2048. Non-modifiable after the profile is referenced by a pool |
| Configure the block allocation mode | block-alloc-mode on-demand | pre-alloc | Default on-demand. Non-modifiable after being referenced |
| Configure the port selection mode | port-alloc-mode random | sequence | Default random. Non-modifiable after being referenced |
| Configure the reserved port range | reserved-port port-start port-end | Default 0-1023. Non-modifiable after being referenced |
| Configure pre-allocated blocks per user | prealloc-blocks-per-user number | Only effective in pre-alloc mode. Non-modifiable after being referenced |
| Configure the block cooling time | cooling-time second | Range 1-3600, default 120. Modifiable after being referenced |
Configure an Addresses Pool
Section titled “Configure an Addresses Pool”| Operation | Command | Description |
| Enter the system configuration view | configure terminal | - |
| Create an addresses pool | cgnat addresses-pool pool_name [range ip-start ip-end|prefix ip/mask] port-allocation-profile profile_name |
Create a Dynamic CGNAT Instance
Section titled “Create a Dynamic CGNAT Instance”| Operation | Command | Description |
| Enter the system configuration view | configure terminal | - |
| Create a dynamic instance | cgnat instance cgnat_name dynamic [vrf vrf_name] | Enter the CGNAT instance view |
| Bind an address pool | outside-address-pool pool_name | Multiple pools can be bound. Non-modifiable after the instance is bound to an ACL |
| Configure the outside VRF | outside-vrf vrf_name | Non-modifiable after the instance is bound to an ACL |
| Configure the filtering mode | filtering-mode eif | adf | apdf | Default eif |
| Enable hairpinning | hairpining enable | Disabled by default |
| Configure per-user limits | max-user-blocks 1-256 / max-user-ports 1-65535 / max-user-sessions 1-10240 / max-user-create-sessions-rate 1-10240 | |
| Configure session aging | aging-tcp-syn / aging-tcp-established / aging-tcp-fin-rst / aging-udp / aging-icmp 1-262144 | Defaults: 75 / 7440 / 60 / 300 / 60 seconds |
| Configure TCP MSS clamping | tcp-mss 160-9540 | Optional |
| Configure the log mode | log mode port-block | session | Default port-block |
| Disable syslog output | syslog disable | Enabled by default |
| Enable IPFIX export | ipfix enable / ipfix collector ip port src ip port | Global IPFIX configuration refers to the IPFIX CLI manual |
Create a Deterministic CGNAT Instance
Section titled “Create a Deterministic CGNAT Instance”| Operation | Command | Description |
| Enter the system configuration view | configure terminal | - |
| Create a deterministic instance | cgnat instance cgnat_name deterministic [vrf vrf_name] | Enter the instance view |
| Configure the inside address range | inside-address [range ip-start ip-end|prefix ip/mask] | Multiple ranges can be configured. Non-modifiable after the instance is bound to an ACL |
| Bind an address pool and other policies | outside-address-pool, aging-*, static-mapping, etc. | Same semantics as the dynamic instance |
Configure Static Mapping
Section titled “Configure Static Mapping”| Operation | Command | Description |
| Enter the instance view | cgnat instance cgnat_name dynamic | - |
| Configure an address-level static mapping | static-mapping outside ipaddress inside ipaddress [protocol tcp|udp|icmp] | Port unchanged; mappings are created lazily on traffic hits |
| Configure a port-level static mapping | static-mapping outside ipaddress port inside ipaddress port protocol tcp|udp|icmp | Mapping created immediately |
Configure Traffic Diversion
Section titled “Configure Traffic Diversion”| Operation | Command | Description |
| Configure an ACL (refer to the ACL configuration) | e.g. permit source subscriber_prefix | The ACL only describes matching conditions |
| Create a CGNAT binding | cgnat binding binding_name cgnat_name acl_name | Traffic matching the ACL permit rules is diverted to the instance |
| Enter the inside interface view and apply the ACL | interface ethernet | |
| Enter the outside interface view | interface ethernet | No ACL needs to be applied on the outside interface; out2in uses full diversion with session lookup, and non-matching traffic is passed through transparently |
Configure the Syslog Server
Section titled “Configure the Syslog Server”| Operation | Command | Description |
| Enter the system configuration view | configure terminal | - |
| Enter the CGNAT syslog view | cgnat syslog | |
| Configure a syslog server | server number target-ip target_ip protocol tcp|udp port l4_port [src-ip src_ip | vrf vrf_name] | Up to 8 servers |
Display and Maintenance
Section titled “Display and Maintenance”| Operation | Command | Description |
| Display CGNAT-enabled interfaces and zones | show cgnat interface | - |
| Display instance configuration and bound ACL status | show cgnat instance config [name instance_name] | |
| Display CGNAT bindings | show cgnat binding | |
| Display port allocation profiles | show cgnat port-allocation-profile [name profile_name] | |
| Display address pools | show cgnat addresses-pool [config|resource-status [name pool_name]] | |
| Display instance resource usage | show cgnat instance resource-status [name instance_name] | Check port block exhaustion |
Configuration Example
Section titled “Configuration Example”Network requirements
Subscribers in the address range 100.64.1.0/24 are connected to Ethernet14 (inside zone). The device translates their traffic to the public pool 23.159.240.0/24 and forwards it through Ethernet15 (outside zone). Port blocks of 2048 ports are allocated on demand, and port-block logs are sent to the syslog server 192.0.2.200.

Configuration steps
- Configure basic IP addresses and enable CGNAT globally.
sonic(config)# interface ethernet 14sonic(config-if-14)# ip address 100.64.1.1/24sonic(config-if-14)# interface ethernet 15sonic(config-if-15)# ip address 23.159.240.254/24sonic(config)# cgnat enable- Configure the ACL matching the subscriber range (refer to the ACL configuration for ACL rule syntax).
sonic(config)# access-list L3 acl1 ingresssonic(config-L3-acl-acl1)# rule 1 src-ip 100.64.1.0/24 packet-action permit- Configure the port allocation profile and the addresses pool.
sonic(config)# cgnat port-allocation-profile pprof1sonic(config-cgnat-port-allocation-profile-pprof1)# block-size 2048sonic(config-cgnat-port-allocation-profile-pprof1)# block-alloc-mode on-demandsonic(config-cgnat-port-allocation-profile-pprof1)# port-alloc-mode randomsonic(config-cgnat-port-allocation-profile-pprof1)# reserved-port 0 1023sonic(config-cgnat-port-allocation-profile-pprof1)# cooling-time 120sonic(config)# cgnat addresses-pool pool1 range 23.159.240.1 23.159.240.253 port-allocation-profile pprof1- Create the dynamic instance and configure its policies.
sonic(config)# cgnat instance cgnat1 dynamicsonic(config-cgnat-instance-dynamic-cgnat1)# outside-address-pool pool1sonic(config-cgnat-instance-dynamic-cgnat1)# filtering-mode eifsonic(config-cgnat-instance-dynamic-cgnat1)# hairpining enablesonic(config-cgnat-instance-dynamic-cgnat1)# max-user-blocks 4sonic(config-cgnat-instance-dynamic-cgnat1)# max-user-ports 8192sonic(config-cgnat-instance-dynamic-cgnat1)# max-user-sessions 4096sonic(config-cgnat-instance-dynamic-cgnat1)# aging-udp 300sonic(config-cgnat-instance-dynamic-cgnat1)# log mode port-block- Create the binding and configure the interface zones.
sonic(config)# cgnat binding bind1 cgnat1 acl1sonic(config)# interface ethernet 14sonic(config-if-14)# acl acl1 priority 1sonic(config-if-14)# cgnat-zone insidesonic(config)# interface ethernet 15sonic(config-if-15)# cgnat-zone outside- Configure the syslog server (optional, for traceability).
sonic(config)# cgnat syslogsonic(config-cgnat-syslog)# server 1 target-ip 192.0.2.200 protocol udp port 514Verify configuration
sonic# show cgnat interfacesonic# show cgnat instance config cgnat1sonic# show cgnat bindingSend traffic from a subscriber (e.g. 100.64.1.11) to a public server. The packet should be translated with its source rewritten to an address in 23.159.240.0/24 and a port within a 2048-port block, and return traffic should be translated back:
Before translation: 100.64.1.11:51234 -> 198.51.100.10:80After translation: 23.159.240.1:4100 -> 198.51.100.10:80Check resource usage and sessions on the device:
sonic# show cgnat instance resource-status name cgnat1Port block allocation/release logs should be visible on the syslog server.