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.
- 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
- In the left menu, select Virtual Data Centers → the VDC → Edges, and click the router row in the Edges table. The router page opens.
- Click Add rule in the header of the NAT rules section. The NAT rule <N> block appears.
- Select SNAT, DNAT or biNAT in the Action field. The default is SNAT. For biNAT, see the More section.
- Select the external network of the router in the Network field.
- Select the protocol in the Protocol field: for SNAT — IP, any protocol; for DNAT — TCP or UDP.
- Fill in the address and port fields as shown in the table below.
- 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
- 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.10from the external network — the web server of the VM192.0.2.20responds.
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.
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
- Start and stop a router and apply rules
- Routers — when rules take effect.
API methods: edge-add-nat-rule, edge-remove-nat-rule, edge-list-rules, edge-deploy-rules — in the API reference.