> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/upg/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/upg/latest/deployment-guides/basic-nat.md).

# Basic NAT

User Plane Gateway (UPG) supports basic NAT on the SGi interface for [Packet Gateway (PGW)](https://docs.cennso.com/components/upg/latest/deployment-guides/pgw.md) and [Traffic Detection Function (TDF)](https://docs.cennso.com/components/upg/latest/deployment-guides/tdf.md) deployments. Basic NAT uses late-binding: mappings are allocated dynamically in the datapath when the first packet of a flow is forwarded, with no Control Plane involvement. This is the main difference from [CG-NAT](https://docs.cennso.com/components/upg/latest/operation-guides/cg-nat.md), where the Control Plane pre-allocates a NAT port block per PFCP session.

> [!NOTE]
> **Limitation:** Basic NAT is currently incompatible with NAT on additional data interfaces — all translations share the SGi NWI's address pool regardless of egress. This applies to both `basic` and `nat44-ei` types.

## NAT types

UPG basic NAT supports two types, configured through the **nat.type** parameter:

- `basic` — endpoint-dependent NAT (NAT44-ED). A separate mapping is created for each destination IP and port pair, so the outside port allocated for an internal source depends on the destination it talks to.
- `nat44-ei` — endpoint-independent NAT (NAT44-EI). The same internal source is always translated to the same outside IP and port regardless of destination, allowing external hosts to reach the UE through that mapping.

> [!NOTE]
> `nat44-ei` is an alpha feature and is not suitable for production deployments.

## Configuration

For a complete deployment, follow the [Packet Gateway](https://docs.cennso.com/components/upg/latest/deployment-guides/pgw.md) guide and add the basic NAT configuration to the **spec** of the `UPGDeployment` CR.

Add the following to the `UPGDeployment` values:

```yaml
spec:
  nat:
    enabled: true
    type: basic

  instances:
    inst01:
      nat:
        ranges:
          - start: 10.100.0.2
            end: 10.100.7.254
```

The **spec.nat.enabled** flag activates NAT, and **spec.nat.type** selects the type (`basic` or `nat44-ei`). The **spec.instances.{name}.nat.ranges** list defines the NAT pool address ranges on the SGi interface.

The **spec.nat.maxNatFlows** field sets the maximum number of concurrent NAT sessions tracked across all worker threads (default `1000000`). When the table is full, new flows are dropped until idle sessions are reaped.

Per-protocol session idle timeouts (in seconds) are set under **spec.nat.timeouts**:

- **icmp** — ICMP idle timeout (default `60`)
- **tcpEstablished** — TCP established idle timeout (default `1800`)
- **tcpTransitory** — TCP transitory idle timeout (default `240`)
- **udp** — UDP idle timeout (default `300`)

For the full list of NAT parameters, see the [UPGDeployment](https://docs.cennso.com/components/upg/latest/technical-reference/crds/UPGDeployment.md) CRD reference.

## TCP MSS clamping

To rewrite the TCP Maximum Segment Size (MSS) on packets passing through basic NAT, set **spec.nat.mssClamping** to the desired MSS value:

```yaml
spec:
  nat:
    enabled: true
    type: basic
    mssClamping: 1400
```

When **spec.nat.mssClamping** is not set, MSS clamping is disabled. MSS clamping applies to both `basic` and `nat44-ei` types.

## Verification

Check the basic NAT state with `vppctl` in the UPG pod. The commands differ between the two NAT types. Use the `nat44 ...` form for `basic` and the `nat44 ei ...` form for `nat44-ei`.

1. Confirm the NAT pool addresses are registered:

   ```bash
   vppctl show nat44 addresses
   ```

   Sample output:

   ```txt
   NAT44 pool addresses:
   10.100.0.2
     tenant VRF: 200
   10.100.0.3
     tenant VRF: 200
   ...
   10.100.7.254
     tenant VRF: 200
   NAT44 twice-nat pool addresses:
   ```

2. Confirm the SGi interface is set as the NAT outside interface:

   ```bash
   vppctl show nat44 interfaces
   ```

   Sample output:

   ```txt
   NAT44 interfaces:
    sgi output-feature in out
   ```

3. Confirm the MSS clamping value, when **spec.nat.mssClamping** is set:

   ```bash
   vppctl show nat mss-clamping
   ```

   Sample output:

   ```txt
   mss-clamping 1400
   ```

   When MSS clamping is not configured, the output is `mss-clamping disabled`.

4. After traffic has flowed, list the active translations:

   ```bash
   vppctl show nat44 sessions
   ```

   Sample output:

   ```txt
   NAT44 ED sessions:
   -------- thread 0 vpp_main: 0 sessions --------
   -------- thread 1 vpp_wk_0: 7 sessions --------
       i2o 10.6.170.124 proto ICMP port 21 fib 2
       o2i 10.100.5.134 proto ICMP port 15057 fib 2
          external host 198.19.0.100:21
          ...
          index 0
          last heard 361.23
          timeout in 56.26
          total pkts 8, total bytes 728
          dynamic translation
       ...
   -------- thread 2 vpp_wk_1: 11 sessions --------
       ...
   ```

   Each worker thread reports the sessions it owns. The `i2o`/`o2i` lines show the pre-NAT and post-NAT 5-tuple for the inbound-to-outbound and outbound-to-inbound directions.

For `nat44-ei`, replace `nat44` with `nat44 ei` in the commands above (for example, `vppctl show nat44 ei addresses`).
