# Networking: NAT gateway ErrorPortAllocation / SNAT port exhaustion — intermittent outbound connection timeouts

**Code:** `NAT gateway SNAT port exhaustion (ErrorPortAllocation)` · **Category:** Networking · **Seen on:** AWS, Azure, Networking

Many instances share few public IPs, and the NAT gateway runs out of source ports for outbound connections.

## Meaning

Each outbound connection to the same destination IP:port uses one SNAT port, so busy services hit the limit and new connections time out. Reuse connections, add public IPs (AWS: more EIPs; Azure: more frontend IPs), reduce idle timeouts, or use private endpoints for cloud services.

## Common causes

- Many connections to the same destination
- No connection reuse in the app
- Too few public IPs on the NAT gateway
- Long idle timeout holding ports
- Calls to cloud APIs through NAT instead of private endpoints

## Quick fix

1. Check the gateway metric (`ErrorPortAllocation`)
2. Add public IPs/frontends
3. Use connection pooling and private endpoints

## Detailed fix by platform

### Shell

1. `aws cloudwatch get-metric-statistics --namespace AWS/NATGateway --metric-name ErrorPortAllocation --dimensions Name=NatGatewayId,Value=nat-0abc --start-time 2026-10-29T00:00:00Z --end-time 2026-10-29T06:00:00Z --period 300 --statistics Sum`

## How to diagnose

1. **ErrorPortAllocation** — Non-zero?
2. **Public IPs** — Enough?
3. **Connections** — Reused?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/networking/nat-gateway-snat-port-exhaustion)
