---
id: ccna-nat-snat
title: "NAT, SNAT và DNAT"
track: nat-hybrid
trackTitle: "NAT, SNAT và hybrid routing"
order: 1
level: core
status: published
estimatedMinutes: 35
prerequisites:
  - ccna-routing-gateway
next: ccna-hybrid-routing
reviewedAgainst: 2026-10-29
sources:
  - title: "RFC 3022"
    url: https://www.rfc-editor.org/rfc/rfc3022
---

# NAT, SNAT và DNAT

Subnet private không ra Internet trực tiếp — cloud gom egress qua vài IP public (PAT/overload). User vào app qua LB/Ingress thì IP đích bị đổi vào Pod. Lẫn hai chiều là debug sai hướng.

## Để làm gì

Giải thích egress chập chờn sau scale-out và path user → Service → Pod.

## Gồm những gì

SNAT (đi ra), DNAT (vào), giới hạn port trên mỗi IP public. Map sang NAT Gateway, Load Balancer, kube-proxy.

## Dùng khi nào

API outbound lúc được lúc không; Ingress timeout dù Pod `curl localhost` vẫn 200.

<div class="net-flow">
<div class="net-step" style="--layer:#dbeafe"><b>Pod private</b><span>SNAT → IP public</span></div>
<div class="net-arrow">→</div>
<div class="net-step" style="--layer:#fef3c7"><b>Internet</b></div>
<div class="net-arrow">←</div>
<div class="net-step" style="--layer:#dcfce7"><b>Client</b><span>LB DNAT → Pod</span></div>
</div>

Nhiều connection cùng lúc trên **một** IP SNAT → hết cổng (~64k). Triệu chứng hay gặp: thêm node là outbound nhiễu, retry thì qua. Fix: thêm IP SNAT / NAT Gateway riêng, không chỉ restart pod.

```bash
curl -s https://ifconfig.me   # từ pod/node private
ss -tn | head
```

## Checklist

- [ ] Biết egress đang SNAT qua IP n nào trên platform.
- [ ] Incident trong cluster vs ngoài Internet — tách SNAT và DNAT.

## Thẻ ôn

### ccna-nat-snat-direction
kind: distinguish
cue: "pod gọi API ngoài"

Q: NAT đổi source hay destination?

A: Source (SNAT) trên biên egress.

### ccna-nat-snat-exhaust
kind: trap
cue: "scale out" + "egress lúc được lúc không"

Q: Một hướng điều tra?

A: SNAT/port exhaustion trên IP public hạn chế.

## Tiếp theo

[Hybrid routing và VPN](./02-hybrid-routing.md)
