> Documentation index for agents: /hcp/3.3/en/llms.txt

# Configure NAT rules

NAT rules replace addresses in packets that pass through the router. They are typically used for two tasks: access from the virtual machines (VMs) of an internal network to an external network (SNAT), and access to a VM service from an external network (DNAT).

## Before you begin

- You need the **Cluster master** role, or you must be the **VDC admin** who created the router.
- The router is connected to an internal and an external network — [Create a router and connect networks to it](/hcp/3.3/en/edges/create-edge/index.md).
- You know the address of the router port in the external network: it is in the **IP** column of the **Networks** section on the router page.
- To apply rules, the router must have the **Started** status.

In the examples: the internal network is `192.0.2.0/24`, the router address in the external network is `203.0.113.10`, and the VM with a web server is `192.0.2.20`.

## 1. Add a rule

1. In the left menu, select **Virtual Data Centers** → the VDC → **Edges**, and click the router row in the **Edges** table. The router page opens.
2. Click **Add rule** in the header of the **NAT rules** section. The **NAT rule \<N>** block appears.
3. Select **SNAT**, **DNAT** or **biNAT** in the **Action** field. The default is **SNAT**. For **biNAT**, see the [More](#more) section.
4. Select the external network of the router in the **Network** field.
5. Select the protocol in the **Protocol** field: for SNAT — **IP**, any protocol; for DNAT — **TCP** or **UDP**.
6. Fill in the address and port fields as shown in the table below.
7. Click **Save Rule**. The web interface shows **NAT rule was successfully added!**.

| Field | SNAT: VM access to the external network | DNAT: access to the VM web server from the external network |
| - | - | - |
| **From (CIDR)** | `192.0.2.0/24` — the internal network | `0.0.0.0/0` — any source |
| **Dst. (CIDR)** | `0.0.0.0/0` — any address | `203.0.113.10/32` — the router address |
| **Dst. Port** | not used | `443` |
| **NAT IP** | `203.0.113.10` — the router address | `192.0.2.20` — the VM address |
| **NAT Port** | not used | `443` |

Center passes ports to the router only in a DNAT rule with the **TCP** or **UDP** protocol; in other rules, ports have no effect.

A rule applies to the router port in the network selected in the **Network** field. SNAT replaces the source address of packets that the router sends through this port. DNAT replaces the destination address of packets that arrive at this port. biNAT does both. If several NAT rules match a packet, the first one applies. Assign NAT rule numbers with the same number of digits, for example from 100 to 900.

## 2. Apply the rules

1. Click **Apply rules** at the bottom of the router page. Center sends all saved NAT and firewall rules to the router.

The button is unavailable while the router does not have the **Started** status or is still booting.

## Check the result

The web interface shows a notification that the rules were applied successfully.

- SNAT: from a VM of the internal network, open an address in the external network — the reply arrives, and the external side sees the address `203.0.113.10`.
- DNAT: open `https://203.0.113.10` from the external network — the web server of the VM `192.0.2.20` responds.

If the rule does not take effect, check that you clicked **Apply rules** after saving and that the router firewall rules do not block this traffic — [Configure firewall rules](/hcp/3.3/en/edges/configure-firewall-rules/index.md).

## More

- Enter **NAT IP** without a mask: with a mask, the web interface accepts the rule, but Center does not save it.

- **biNAT** — a permanent one-to-one mapping between the address in **From (CIDR)** and the external address in **NAT IP**.

- "#" — the rule number. The web interface suggests a number 100 higher than the largest one.

- To delete a rule, click the trash icon in the rule row, and then click **Delete** in the confirmation window. A deleted rule stops taking effect after you click **Apply rules**.

## Next

- [Configure firewall rules](/hcp/3.3/en/edges/configure-firewall-rules/index.md)
- [Start and stop a router and apply rules](/hcp/3.3/en/edges/manage-edge/index.md)
- [Routers](/hcp/3.3/en/edges/index.md) — when rules take effect.

API methods: `edge-add-nat-rule`, `edge-remove-nat-rule`, `edge-list-rules`, `edge-deploy-rules` — in the [API reference](/hcp/3.3/en/api/methods/index.md).
