跳转到内容
Ask AI

CGNAT Configuration

此内容尚不支持你的语言。

[Command]

show cgnat interface

[Purpose]

Display the interfaces on which CGNAT is enabled and their zone (inside or outside).

[View]

System view

[Use Cases]

sonic# show cgnat interface
+-------------+--------------+
| INTERFACE | CGNAT_ZONE |
+=============+==============+
| Ethernet14 | inside |
+-------------+--------------+
| Ethernet15 | outside |
+-------------+--------------+

show cgnat instance config [name instance_name]

Section titled “show cgnat instance config [name instance_name]”

[Command]

show cgnat instance config [name instance_name]

[Purpose]

Display the detailed configuration of CGNAT instance(s) and the status of the bound ACL.

[Parameter]

instance_nameOptional. The name of a CGNAT instance. If not specified, all instances are displayed

[View]

System view

[Use Cases]

sonic# show cgnat instance config

[Command]

show cgnat binding

[Purpose]

Display the current CGNAT bindings, including the binding name, bound instance, ACL and binding status.

[View]

System view

[Use Cases]

sonic# show cgnat binding

show cgnat port-allocation-profile [name profile_name]

Section titled “show cgnat port-allocation-profile [name profile_name]”

[Command]

show cgnat port-allocation-profile [name profile_name]

[Purpose]

Display the configured CGNAT port allocation profiles and their reference (bound) status.

[Parameter]

profile_nameOptional. The name of a port allocation profile. If not specified, all profiles are displayed

[View]

System view

[Use Cases]

sonic# show cgnat port-allocation-profile

show cgnat addresses-pool [config {name addresses-pool_name} | resource-status {name addresses-pool_name}]

Section titled “show cgnat addresses-pool [config {name addresses-pool_name} | resource-status {name addresses-pool_name}]”

[Command]

show cgnat addresses-pool [config {name addresses-pool_name} | resource-status {name addresses-pool_name}]

[Purpose]

Display the configured CGNAT address pools, including address ranges, bound port allocation profiles, reference status and block statistics.

[Parameter]

addresses-pool_nameOptional. The name of an address pool. If not specified, all pools are displayed

[View]

System view

[Use Cases]

sonic# show cgnat addresses-pool config

show cgnat instance resource-status [name instance_name]

Section titled “show cgnat instance resource-status [name instance_name]”

[Command]

show cgnat instance resource-status [name instance_name]

[Purpose]

Display the port block allocation status and resource usage of CGNAT instance(s), including the number of total/allocated/cooling blocks and active users. Used to check resource exhaustion during operation.

[Parameter]

instance_nameOptional. The name of a CGNAT instance. If not specified, all instances are displayed

[View]

System view

[Use Cases]

sonic# show cgnat instance resource-status

[Command]

cgnat enable

[Purpose]

Enable cgnat globally

[View]

System configuration view

[Use Cases]

sonic# configure terminal
sonic(config)# cgnat enable

cgnat port-allocation-profile profile_name

Section titled “cgnat port-allocation-profile profile_name”

[Command]

cgnat port-allocation-profile profile_name

[Purpose]

Create a CGNAT port allocation profile and enter the port-allocation-profile view. The port allocation profile defines the port block allocation policy , including block size, block allocation mode, port allocation mode, reserved port range and block cooling time.

[Parameter]

profile_nameThe name of the port allocation profile

[View]

System configuration view

[Notes]

The parameters marked as non-modifiable below cannot be changed once the profile is referenced (bound) by an address pool.

[Use Cases]

sonic# configure terminal
sonic(config)# cgnat port-allocation-profile test1
sonic(config-cgnat-port-allocation-profile-test1)#

[Command]

block-size block_size

[Purpose]

Configure the number of ports contained in one port block. The public IP port range of the pool is divided into port blocks according to this size, and each block is allocated to a user as a whole.

[Parameter]

block_sizeThe number of ports per block. Default: 2048

[View]

Port-allocation-profile view

[Notes]

This command cannot be modified after the profile is referenced by an address pool.

[Use Cases]

sonic(config-cgnat-port-allocation-profile-test1)# block-size 2048

[Command]

block-alloc-mode on-demand | pre-alloc

[Purpose]

Configure the port block allocation mode.

[Parameter]

on-demandAllocate a port block to a user only when the user actually needs ports (default)
pre-allocPre-allocate a fixed number of port blocks to each user. The number is specified by prealloc-blocks-per-user

[View]

Port-allocation-profile view

[Notes]

This command cannot be modified after the profile is referenced by an address pool.

[Use Cases]

sonic(config-cgnat-port-allocation-profile-test1)# block-alloc-mode on-demand

[Command]

port-alloc-mode [random | sequence]

[Purpose]

Configure the port selection mode within a port block.

[Parameter]

randomAllocate ports randomly within the block (default)
sequenceAllocate ports sequentially within the block

[View]

Port-allocation-profile view

[Notes]

This command cannot be modified after the profile is referenced by an address pool.

[Use Cases]

sonic(config-cgnat-port-allocation-profile-test1)# port-alloc-mode random

[Command]

reserved-port port-start port-end

[Purpose]

Configure the reserved (excluded) port range at the beginning of the port range. Reserved ports do not participate in port block division or allocation.

[Parameter]

port-startThe start of the reserved port range
port-endThe end of the reserved port range. Default: 1023

[View]

Port-allocation-profile view

[Notes]

This command cannot be modified after the profile is referenced by an address pool.

[Use Cases]

sonic(config-cgnat-port-allocation-profile-test1)# reserved-port 0 1023

[Command]

prealloc-blocks-per-user number

[Purpose]

Configure the number of port blocks pre-allocated to each user. Only effective when block-alloc-mode is pre-alloc.

[Parameter]

numberThe number of pre-allocated blocks per user

[View]

Port-allocation-profile view

[Notes]

This command cannot be modified after the profile is referenced by an address pool.

[Use Cases]

sonic(config-cgnat-port-allocation-profile-test1)# prealloc-blocks-per-user 1

[Command]

cooling-time second

[Purpose]

Configure the cooling time of a released port block. A block enters the COOLING state after being released and cannot be re-allocated to other users until the cooling time expires. This prevents packets of the old user from being forwarded to a new user by mistake.

[Parameter]

secondThe cooling time in seconds. Range: 1-3600. Default: 120

[View]

Port-allocation-profile view

[Notes]

Modifiable after binding.

[Use Cases]

sonic(config-cgnat-port-allocation-profile-test1)# cooling-time 120

cgnat addresses-pool pool_name [range ip-start ip-end|prefix ip/mask] port-allocation-profile profile_name

Section titled “cgnat addresses-pool pool_name [range ip-start ip-end|prefix ip/mask] port-allocation-profile profile_name”

[Command]

cgnat addresses-pool pool_name [range ip-start ip-end|prefix ip/mask] port-allocation-profile profile_name

[Purpose]

Create a CGNAT public address pool. The pool defines the public IPv4 addresses used for dynamic port block allocation, and binds a port allocation profile.

[Parameter]

pool_nameThe name of the address pool
range ip-start ip-endSpecify the public address range by start and end IP addresses
prefix ip/maskSpecify the public address range by a prefix
profile_nameThe port allocation profile referenced by the pool

[View]

System configuration view

[Notes]

The address range of a pool supports dynamic expansion (adding addresses), but does not support shrinking.

[Use Cases]

sonic(config)# cgnat addresses-pool pool1 range 23.159.240.1 23.159.240.254 port-allocation-profile test1

cgnat instance cgnat_name dynamic [vrf vrf_name]

Section titled “cgnat instance cgnat_name dynamic [vrf vrf_name]”

[Command]

cgnat instance cgnat_name dynamic [vrf vrf_name]

[Purpose]

Create a CGNAT instance in dynamic (Port Block Allocation) mode and enter the instance view. Dynamic mode allocates public IP and ports to users on demand or by pre-allocation in units of port blocks. All instances share the inside VRF where user traffic resides; vrf specifies the VRF of the instance itself.

[Parameter]

cgnat_nameThe name of the CGNAT instance
vrf vrf_nameThe VRF of the instance. If not specified, the default VRF is used

[View]

System configuration view

[Use Cases]

sonic(config)# cgnat instance cgnat1 dynamic
sonic(config-cgnat-instance-dynamic-cgnat1)#

[Command]

outside-address-pool pool_name

[Purpose]

Bind a public address pool to the instance. The public IP and ports of dynamic sessions are allocated from the bound pools. Multiple pools can be configured.

[Parameter]

pool_nameThe name of an existing CGNAT address pool

[View]

CGNAT instance view

[Notes]

This command cannot be modified after the instance is bound to an ACL (see cgnat binding).

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# outside-address-pool pool1

[Command]

outside-vrf vrf_name

[Purpose]

Configure the VRF used when the instance forwards traffic to the public network side (the VRF where the public address pool is reachable).

[Parameter]

vrf_nameThe name of the outside VRF

[View]

CGNAT instance view

[Notes]

This command cannot be modified after the instance is bound to an ACL.

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# outside-vrf Vrf124

[Command]

filtering-mode [eif |adf |apdf]

[Purpose]

Configure the outbound-to-inbound filtering behavior of the instance, that is, whether packets from external hosts are allowed to pass through an existing mapping.

[Parameter]

eifEndpoint-Independent Filtering (endpoint-independent filtering / full cone behavior). As long as the mapping exists, any external host can send packets to the public IP:port. Default, maximizes P2P application compatibility
adfAddress-Dependent Filtering (address-dependent filtering). Only packets from the external IP address that the user has already communicated with are allowed
apdfAddress-Port-Dependent Filtering (address-and-port-dependent filtering). Only packets from the external IP address and port that the user has already communicated with are allowed

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# filtering-mode eif

[Command]

hairpining enable

[Purpose]

Enable hairpining (hairpin NAT). After it is enabled, users on the inside of the same CGNAT instance can access each other through the peer’s public mapping address.

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# hairpining enable

[Command]

max-user-blocks 1-256

[Purpose]

Configure the maximum number of port blocks that a single user (inside source IP) can own at the same time. When the limit is reached, the user cannot apply for new port blocks.

[Parameter]

1-256The maximum number of port blocks per user

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# max-user-blocks 4

[Command]

max-user-ports 1-65535

[Purpose]

Configure the maximum number of ports that a single user (inside source IP) can occupy at the same time. Together with max-user-blocks, it limits the public port resources a user can consume.

[Parameter]

1-65535The maximum number of ports per user

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# max-user-ports 8192

[Command]

max-user-sessions 1-10240

[Purpose]

Configure the maximum number of concurrent sessions of a single user (inside source IP). New sessions beyond the limit are discarded. If not configured, the number of concurrent sessions per user is not limited.

[Parameter]

1-10240The maximum number of concurrent sessions per user

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# max-user-sessions 4096

[Command]

max-user-create-sessions-rate 1-10240

[Purpose]

Configure the maximum session creation rate of a single user (inside source IP), in sessions per second. Statistics are calculated in a rolling 1-second cycle. New sessions beyond the limit are discarded.

[Parameter]

1-10240The maximum number of new sessions per second per user

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# max-user-create-sessions-rate 200

[Command]

aging-tcp-syn 1-262144

[Purpose]

Configure the aging time of TCP sessions in the SYN-SENT / SYN-RCVD state, to limit the resource occupation of abnormal half-open connections.

[Parameter]

1-262144The aging time in seconds

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# aging-tcp-syn 75

[Command]

aging-tcp-established 1-262144

[Purpose]

Configure the aging time of TCP sessions in the ESTABLISHED state. The aging timer is refreshed when packets pass through the session.

[Parameter]

1-262144The aging time in seconds

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# aging-tcp-established 7440

[Command]

aging-tcp-fin-rst 1-262144

[Purpose]

Configure the aging time of TCP sessions after the connection is closed (FIN/RST received). The session is deleted when the timer expires and the occupied resources are released.

[Parameter]

1-262144The aging time in seconds

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# aging-tcp-fin-rst 60

[Command]

aging-udp 1-262144

[Purpose]

Configure the aging time of UDP sessions. The aging timer is refreshed when packets pass through the session.

[Parameter]

1-262144The aging time in seconds

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# aging-udp 300

[Command]

aging-icmp 1-262144

[Purpose]

Configure the aging time of ICMP (Echo Request/Reply) sessions.

[Parameter]

1-262144The aging time in seconds

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# aging-icmp 60

[Command]

tcp-mss 160-9540

[Purpose]

Configure the TCP MSS clamping value. The MSS option in TCP packets passing through the CGNAT instance is adjusted to this value when it exceeds it, to avoid IP fragmentation caused by MTU reduction.

[Parameter]

160-9540The MSS clamping value in bytes

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# tcp-mss 1460

[Command]

log mode [port-block | session]

[Purpose]

Configure the traceability log mode of the instance.

[Parameter]

port-blockPort block log. Logs are recorded only when a port block is allocated or released. The log volume is about 1/1000 of session-level logging (default, recommended)
sessionSession-level log. One log is recorded for each mapping creation and deletion, for fine-grained audit

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# log mode port-block

[Command]

syslog disable

[Purpose]

Disable syslog output for the instance. By default, syslog output is enabled when the log mode and syslog server are configured.

[View]

CGNAT instance view

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# syslog disable

[Command]

ipfix enable

[Purpose]

Enable IPFIX export for the instance. Port block allocation/release and session create/delete events are exported to the IPFIX collector.

[View]

CGNAT instance view

[Notes]

IPFIX collector, template and other related configurations refer to the IPFIX CLI manual. This command only enables IPFIX export on the CGNAT instance.

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# ipfix enable

ipfix collector ipaddress port src ipaddress port

Section titled “ipfix collector ipaddress port src ipaddress port”

[Command]

ipfix collector ipaddress port src ipaddress port

[Purpose]

Configure the IPFIX collector address and the local source address/port used to send IPFIX packets for the instance.

[Parameter]

ipaddress portThe IPv4 address and UDP port of the IPFIX collector
src ipaddress portThe local source IPv4 address and UDP port of IPFIX packets

[View]

CGNAT instance view

[Notes]

The global IPFIX configuration (exporter, template, etc.) refers to the IPFIX CLI manual. This command only specifies the destination and source parameters for the CGNAT instance.

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# ipfix collector 192.0.2.100 4739 src 23.159.240.254 4739

static-mapping outside ipaddress inside ipaddress [protocol {tcp| udp| icmp}]

Section titled “static-mapping outside ipaddress inside ipaddress [protocol {tcp| udp| icmp}]”

[Command]

static-mapping outside ipaddress inside ipaddress [protocol {tcp| udp| icmp}]

[Purpose]

Configure an address-level static CGNAT mapping: outside_ip ↔ inside_ip, with the port kept unchanged. The outside (public) address must belong to the static address pool, which is isolated from the dynamic CGNAT address pool.

[Parameter]

outside ipaddressThe public IPv4 address (static pool)
inside ipaddressThe private IPv4 address
protocolOptional. tcp, udp or icmp. If not specified, all protocols are matched (equivalent to all)

[View]

CGNAT instance view

[Notes]

An address-level static mapping does not create mappings for all 65535 ports. It is stored in the static address table, and an exact mapping is created lazily only when traffic hits a specific port. Conflict checks are performed when the mapping is created: 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) cannot be configured repeatedly; a static mapping cannot cover an existing dynamic mapping with the same inside endpoint.

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)#
static-mapping outside 203.0.113.11 inside 10.0.0.11 protocol tcp

static-mapping outside ipaddress port inside ipaddress port protocol [tcp|udp|icmp]

Section titled “static-mapping outside ipaddress port inside ipaddress port protocol [tcp|udp|icmp]”

[Command]

static-mapping outside ipaddress port inside ipaddress port protocol [tcp|udp|icmp]

[Purpose]

Configure a port-level static CGNAT mapping: outside_ip:outside_port ↔ inside_ip:inside_port. The mapping table is created immediately upon configuration.

[Parameter]

outside ipaddress portThe public IPv4 address and port (static pool)
inside ipaddress portThe private IPv4 address and port
protocoltcp, udp or icmp

[View]

CGNAT instance view

[Notes]

The conflict check rules are the same as the address-level static mapping: outside endpoints and inside endpoints cannot be duplicated, address-level and port-level rules of the same protocol on the same IP are mutually exclusive, and a static mapping cannot cover an existing dynamic mapping.

[Use Cases]

sonic(config-cgnat-instance-dynamic-cgnat1)# static-mapping outside 203.0.113.10 8080 inside 10.0.0.10 80 protocol tcp

cgnat instance cgnat_name deterministic [vrf vrf_name]

Section titled “cgnat instance cgnat_name deterministic [vrf vrf_name]”

[Command]

cgnat instance cgnat_name deterministic [vrf vrf_name]

[Purpose]

Create a CGNAT instance in deterministic (Deterministic NAT) mode and enter the instance view. In this mode, the mapping relationship between each inside address and the public address + port block is derived from a fixed algorithm: the port block of each inside user is calculated from the inside/outside address ratio, so the mapping can be reverse-derived without maintaining the runtime binding state. Suitable for traceability scenarios that require algorithmic reverse lookup.

[Parameter]

cgnat_nameThe name of the CGNAT instance
vrf vrf_nameThe VRF of the instance. If not specified, the default VRF is used

[View]

System configuration view

[Notes]

The deterministic instance view supports the following sub-commands. Except for inside-address , they have the same semantics as the dynamic instance and are not repeated here: outside-address-pool, outside-vrf, hairpinning enable, max-user-sessions, max-user-create-sessions-rate, aging-tcp-syn, aging-tcp-established, aging-tcp-fin-rst, aging-udp, aging-icmp, tcp-mss, syslog disable, ipfix enable, ipfix collector, static-mapping.

[Use Cases]

sonic(config)# cgnat instance cgnat2 deterministic
sonic(config-cgnat-instance-deterministic-cgnat2)#

inside-address [range ip-start ip-end|prefix ip/mask]

Section titled “inside-address [range ip-start ip-end|prefix ip/mask]”

[Command]

inside-address [range ip-start ip-end|prefix ip/mask]

[Purpose]

Configure the inside address range of the deterministic instance. The deterministic mapping (inside address → public IP + port block) is derived from the ratio of the inside address count to the outside address count. Multiple inside address ranges can be configured.

[Parameter]

range ip-start ip-endSpecify the inside address range by start and end IP addresses
prefix ip/maskSpecify the inside address range by a prefix

[View]

CGNAT (deterministic) instance view

[Notes]

This command cannot be modified after the instance is bound to an ACL.

[Use Cases]

sonic(config-cgnat-instance-deterministic-cgnat2)# inside-address range 10.0.0.1 10.0.3.254

cgnat binding binding_name cgnat_name acl_name

Section titled “cgnat binding binding_name cgnat_name acl_name”

[Command]

cgnat binding binding_name cgnat_name acl_name

[Purpose]

Create a binding between an ACL and a CGNAT instance. Inside traffic matching the permit rules of the ACL is diverted to the CGNAT instance for translation.

[Parameter]

binding_nameThe name of the binding
cgnat_nameThe name of an existing CGNAT instance
acl_nameThe name of an existing ACL

[View]

System configuration view

[Notes]

The ACL is matched in binding priority order. Only permit rules divert traffic to CGNAT; deny rules and non-matched traffic follow normal forwarding. After the instance is bound by a binding, its non-modifiable parameters (address pool, outside VRF, port profile related parameters, etc.) cannot be changed.

[Use Cases]

sonic(config)# cgnat binding bind1 cgnat1 acl1

[Command]

acl acl_name

[Purpose]

Apply an existing ACL to the interface. Together with the CGNAT binding, it implements traffic diversion: the ACL classifies the traffic, and the binding redirects the matched traffic to the CGNAT instance.

[Parameter]

acl_nameThe name of an existing ACL

[View]

Interface view

[Use Cases]

sonic(config)# interface ethernet 4
sonic(config-if-4)# acl acl1

[Command]

cgnat-zone [inside|outside]

[Purpose]

Configure the CGNAT zone of the interface. The zone identifies the direction of traffic on the interface: inside (user side) traffic is translated by the CGNAT instance, and outside (public network side) traffic performs the reverse translation lookup.

[Parameter]

insideThe interface belongs to the inside (user side) zone
outsideThe interface belongs to the outside (public network side) zone

[View]

Interface view

[Use Cases]

sonic(config)# interface ethernet 4
sonic(config-if-4)# cgnat-zone inside
sonic(config)# interface ethernet 8
sonic(config-if-8)# cgnat-zone outside

[Command]

cgnat syslog

[Purpose]

Configure the server information for sending CGNAT syslog logs.

[View]

System configuration view

[Use Cases]

sonic(config)# cgnat syslog
sonic(config-cgnat-syslog)#

server number target-ip target_ip protocol [tcp|udp] port l4_port [src-ip src_ip |vrf vrf_name]

Section titled “server number target-ip target_ip protocol [tcp|udp] port l4_port [src-ip src_ip |vrf vrf_name]”

[Command]

server number target-ip target_ip protocol [tcp|udp] port l4_port [src-ip src_ip |vrf vrf_name]

[Purpose]

Configure the syslog server information to which CGNAT syslog is output.

[Parameter]

numberSyslog server number
target_ipSyslog server IP address
l4_portPort number used by the syslog server

[View]

CGNAT Syslog view

[Use Cases]

sonic(config-cgnat-syslog)# server 1 target-ip 10.10.10.1 protocol udp port 514