Networking

Azure NAT Gateway: rotate outbound IPs before breaking downstream allowlists

A production runbook for rotating Azure NAT Gateway public IPs with downstream allowlist inventory, dual-IP validation, connection evidence and a bounded rollback.

05 Nov 2026 azurenat-gatewaypublic-ipegressallowlistnetworkingobservabilityautomationrunbookvalidationrollbackproduction

An operations team must replace the public IP used by an Azure NAT Gateway. The address may belong to an expiring allocation plan, a new public IP prefix, a network consolidation or a revised partner contract. The Azure change is small. The production change is not: payment APIs, SaaS platforms and managed file transfers may admit traffic only from the current source IP.

Replacing the address in one operation can turn healthy applications into 403, TCP timeout or TLS handshake incidents. Keeping both addresses temporarily is safer, but it is not a traffic-weighted canary. For every new outbound connection, NAT Gateway can select any attached public IP. Removing one of those IPs terminates the active connections associated with it.

The running case is an App Service workload using regional VNet Integration and a NAT Gateway to reach several allowlisted dependencies. The runbook ends with an explicit decision: keep dual IPs, remove the old IP during a bounded reconnection window, roll back the association, or stop because a dependency has not proved the new source.

Freeze the egress contract

Start with the identity that remote systems observe. A NAT Gateway public IP is not an application credential, but an allowlist turns it into part of the access contract.

yaml 01-egress-rotation-contract.yml
change: CHG-2026-1105-12
nat_gateway: nat-app-prod
workload_subnet: snet-app-integration-prod
old_public_ip: 198.51.100.10
new_public_ip: 203.0.113.20

critical_dependencies:
- dependency: partner-api
  protocol: https
  owner: integration-team
  evidence: remote_access_log
- dependency: managed-sftp
  protocol: sftp
  owner: data-operations
  evidence: server_authentication_log

gates:
- effective egress path proved
- every dependency owner identified
- old and new IPs allowed before Azure change
- fresh connections observed from both IPs
- long-lived sessions classified
- rollback keeps old public IP resource

stop_conditions:
- unknown downstream allowlist
- source IP differs from NAT inventory
- non-retryable long-lived session on old IP
- failed SNAT connections or dropped packets increase

Use documentation ranges in the change record, never real production addresses in a reusable runbook. Store the actual IPs, dependency owners and approvals in the controlled evidence pack.

Prove the effective outbound path

Do not rotate the NAT Gateway until the workload is proved to traverse it. A 0.0.0.0/0 user-defined route to a virtual appliance overrides NAT Gateway for that traffic. An incomplete subnet inventory can also leave one App Service integration subnet, node pool or worker subnet on another egress path.

bash 02-inventory-nat-egress.sh
set -eu

RG="rg-network-prod"
NAT="nat-app-prod"

az network nat gateway show --resource-group "$RG" --name "$NAT" --query '{id:id,sku:sku.name,publicIps:publicIpAddresses[].id,publicPrefixes:publicIpPrefixes[].id,subnets:subnets[].id,idleTimeout:idleTimeoutInMinutes}' --output json > nat-before.json

az network vnet subnet list --resource-group "$RG" --vnet-name "vnet-app-prod" --query '[].{name:name,id:id,natGateway:natGateway.id,routeTable:routeTable.id}' --output json > subnets-before.json

jq -r '.publicIps[], .publicPrefixes[]' nat-before.json | while read -r RESOURCE_ID; do
    az resource show --ids "$RESOURCE_ID"       --query '{id:id,location:location,sku:sku.name,properties:properties}'       --output json
  done > outbound-address-resources-before.json

Compare the inventory with a fresh connection from the workload and with the source recorded by a controlled downstream endpoint. An IP echo service is only supporting evidence: a proxy, firewall or service mesh can change the source after the workload. The dependency’s own access log is authoritative for its allowlist decision.

Also capture all public IPs and prefixes already attached. A NAT Gateway can use a combination representing up to 16 addresses, and a new connection can leave through any of them. The allowlist must cover the complete attached set, not only the address returned by one probe.

Inventory consumers before attaching the new IP

Cloud inventory cannot discover every external allowlist. Build the dependency list from application configuration, DNS and firewall logs, service catalogs, secrets that contain endpoint names, and interviews with workload owners. Separate destinations by consequence:

  • request-response APIs that retry safely;
  • queues or webhooks where an ambiguous timeout can duplicate an effect;
  • database or file-transfer sessions that remain open for hours;
  • license servers or vendor control planes with manual allowlist lead time;
  • destinations reached through a proxy and therefore unaffected by this NAT identity.

For each dependency, require positive evidence that both the old and new IP are accepted before changing NAT Gateway. A ticket marked complete is coordination evidence, not network evidence. Run a probe from a controlled canary already using the new IP where possible, or ask the remote owner to show a matching accepted connection in its logs.

If a dependency cannot temporarily allow both addresses, do not use dual-IP coexistence on the production gateway. Prepare a separate canary subnet and NAT Gateway, move a disposable representative client through the approved deployment path, and stop if the remote side cannot validate it.

Add the new IP without replacing the old one

Create a static Standard public IP or an approved prefix compatible with the NAT Gateway SKU and region. Keep its resource after rollback. The update command replaces the public-IP array, so include every existing address as well as the new one.

bash 03-add-new-public-ip.sh
set -eu

RG="rg-network-prod"
NAT="nat-app-prod"
OLD_IP_RESOURCE="pip-nat-app-prod-old"
NEW_IP_RESOURCE="pip-nat-app-prod-new"

az network public-ip create --resource-group "$RG" --name "$NEW_IP_RESOURCE" --sku Standard --allocation-method Static --output json > public-ip-new.json

az network nat gateway update --resource-group "$RG" --name "$NAT" --public-ip-addresses "$OLD_IP_RESOURCE" "$NEW_IP_RESOURCE" --output json > nat-dual-ip.json

az network nat gateway show --resource-group "$RG" --name "$NAT" --query 'publicIpAddresses[].id' --output tsv

Reconcile this command with the captured inventory before execution. If the gateway already uses more addresses or public IP prefixes, the declared update must preserve them. Prefer the repository’s IaC workflow for the durable change; use CLI output as evidence, not as an unmanaged source of truth.

Dual attachment is the start of validation, not proof of cutover. There is no supported assignment of one NAT Gateway public IP to a specific VM, subnet or destination. New connections are distributed across the attached addresses, so production traffic may use the new IP immediately.

Prove both source IPs with fresh connections

Long-lived keep-alive pools can continue on the old mapping and hide an incomplete allowlist. Generate bounded fresh connections from a canary instance in every affected subnet. Close each connection, vary the destination only within the approved test set, and correlate the UTC window with downstream logs.

bash 04-probe-dual-ip-egress.sh
set -eu

ENDPOINT="https://<approved-ip-echo-endpoint>/source"

for ATTEMPT in $(seq 1 40); do
curl --fail --silent --show-error   --connect-timeout 5   --max-time 15   --header 'Connection: close'   "$ENDPOINT"
sleep 2
done | sort | uniq -c

The loop is a discovery aid, not a distribution guarantee. Do not require a 50/50 split and do not infer absence because one address was not selected in a small sample. The production gate is stronger: every configured address is accepted by every critical downstream control, and the remote owner can correlate successful requests from the new IP.

Test business behavior as well as network reachability. For write APIs, use a no-effect operation or a dedicated idempotency key. For SFTP, authenticate to a canary directory without transferring production data. Record DNS result, TCP/TLS timing, HTTP or protocol result, remote source IP and correlation identifier.

Watch NAT and application evidence

Read NAT Gateway platform metrics over a baseline window and the dual-IP window. Use Sum for connection and packet counts, and Average for datapath availability.

bash 05-monitor-nat-rotation.sh
NAT_ID="$(jq -r .id nat-before.json)"
START="2026-11-05T18:00:00Z"
END="2026-11-05T19:00:00Z"

az monitor metrics list --resource "$NAT_ID" --metric SNATConnectionCount TotalConnectionCount PacketDropCount --aggregation Total --interval PT1M --start-time "$START" --end-time "$END" --output json > nat-connection-metrics.json

az monitor metrics list --resource "$NAT_ID" --metric DatapathAvailability --aggregation Average --interval PT1M --start-time "$START" --end-time "$END" --output json > nat-availability-metric.json

Correlate failed SNAT attempts and dropped packets with application timeouts, remote deny logs and retry volume. NAT metrics are not an allowlist audit and do not identify which partner rejected an address. They also do not provide a reliable per-public-IP drain signal for the old address. Use application connection age and downstream evidence for that decision.

NAT Gateway metrics are multidimensional and are not exported through Diagnostic Settings in the same way as ordinary resource logs. If long-term evidence is required, collect the metrics through the Azure Monitor metrics API or an approved monitoring pipeline.

Remove the old IP only inside a reconnection window

Leaving both addresses attached indefinitely enlarges every allowlist and makes the migration state permanent. Removing the old address, however, terminates active connections that use it. There is no honest zero-impact gate based only on Azure configuration.

Classify active protocols before removal. Pause new batch starts, let bounded jobs finish, reduce retry storms and confirm that request-response clients reconnect with backoff and idempotency. For long-lived sessions, agree on a maintenance window and an application-level reconnection plan. If a session cannot be interrupted or safely replayed, keep dual IPs and escalate the architecture decision.

bash 06-remove-old-public-ip.sh
set -eu

RG="rg-network-prod"
NAT="nat-app-prod"
NEW_IP_RESOURCE="pip-nat-app-prod-new"

az network nat gateway update --resource-group "$RG" --name "$NAT" --public-ip-addresses "$NEW_IP_RESOURCE" --output json > nat-new-ip-only.json

az network nat gateway show --resource-group "$RG" --name "$NAT" --query '{publicIps:publicIpAddresses[].id,publicPrefixes:publicIpPrefixes[].id,subnets:subnets[].id}' --output json

Keep the old public IP resource and downstream allowlist entry for the rollback window. A rollback reattaches the old address and restores new connection eligibility; it does not resurrect connections already terminated by removal. The application must reconnect or replay them safely.

Decide, hold or roll back

Remove the old IP only when all affected subnets use the expected gateway, every critical dependency accepts the new source, fresh connections are visible in remote logs, application errors remain at baseline and the reconnection impact is accepted. Then update IaC, observability and the dependency register before removing the old allowlist entry in a separate change.

Hold dual IPs when validation is complete but a long-lived session needs a later maintenance window. Set an owner and expiry date; otherwise temporary coexistence becomes undocumented architecture.

Roll back by reapplying the complete previous public-IP array from the captured state. Stop new jobs, reattach the old address, verify fresh connections through it and retain the new address until the incident is understood. Rollback is incomplete if Azure shows the old IP but a downstream owner has already removed it from the allowlist.

Stop the change when any dependency owner is unknown, the observed source is outside the NAT inventory, a UDR sends traffic elsewhere, or the workload cannot tolerate the forced reconnections caused by removal. The correct outcome can be a postponed rotation with a precise blocker.

The production decision is therefore more specific than “the new IP works”: every configured source is authorized during coexistence, the old connections can be interrupted deliberately, the new-only state is observable, and both Azure and downstream controls retain a tested rollback path.