Home / OCI

OCIRunbookAdvanced

OCI subnet or VCN running out of IP addresses - a runbook for adding, expanding and modifying CIDR blocks

Launches fail because a subnet has no free private IPs. Add a CIDR to the VCN, expand or add CIDRs to the subnet, and update DRG, peering, firewall and on-prem routes so the new range is reachable.

Deepak Bhardwaj7 min read

Applies toOCI Networking VCNs and regional subnets (IPv4), DRG attachments and route distributions, LPG peering, OCI CLI 3.x

Symptom

  • Instance launches, instance pool scale-outs, OKE node pools or load balancer creation fail with an error that the subnet has no available IP addresses.
  • A team needs a new subnet, and every free block in the VCN is used.
  • Growth plans need a larger range than the VCN was built with.

OCI has three ways to add address space, and each has different constraints. Pick the right one before you change anything.

Operation CLI Constraint Disruption
Add a CIDR to the VCN oci network vcn add-vcn-cidr Must not overlap the VCN's CIDRs, peered VCNs or on-prem ranges. Check the current per-VCN CIDR limit None to traffic. The VCN is UPDATING and its subnets, route tables and LPGs can't be changed until it finishes
Change an existing VCN CIDR oci network vcn modify-vcn-cidr New block must contain every subnet and every address used in route rules Same as above
Expand a subnet's CIDR oci network subnet update --cidr-block Same network address, larger range, entirely inside a VCN CIDR None to existing IPs
Add a CIDR to a subnet oci network subnet add-ipv4-subnet-cidr Inside a VCN CIDR, not overlapping other subnets. Check the current per-subnet CIDR limit None

Checks

1. Confirm where the addresses are going

SUBNET=ocid1.subnet.oc1..xxxx
oci network subnet get --subnet-id "$SUBNET" \
  --query 'data.{cidr:"cidr-block", cidrs:"ipv4-cidr-blocks", vcn:"vcn-id", rt:"route-table-id"}'

# Count private IPs in use and see who holds them
oci network private-ip list --subnet-id "$SUBNET" --all \
  --query 'length(data)'
oci network private-ip list --subnet-id "$SUBNET" --all \
  --query 'data[].{ip:"ip-address", name:"display-name", vnic:"vnic-id"}' --output table

OCI reserves the first two and the last address in each subnet CIDR. A /24 gives 253 usable addresses, not 256.

Before you add space, look for leaks: secondary private IPs from deleted apps, OKE VCN-native pods with high max pods per node, load balancer subnets with many old LBs, and detached-but-not-deleted VNICs from test instances. Reclaiming those can be faster than a network change.

2. Map the VCN's address plan

VCN=$(oci network subnet get --subnet-id "$SUBNET" --query 'data."vcn-id"' --raw-output)
oci network vcn get --vcn-id "$VCN" --query 'data."cidr-blocks"'
oci network subnet list -c "$COMP" --vcn-id "$VCN" --all \
  --query 'data[].{name:"display-name", cidr:"cidr-block", extra:"ipv4-cidr-blocks"}' --output table

3. Collect every range the new block must not overlap

  • CIDRs of VCNs peered over LPGs or the DRG (all regions, including remote peering)
  • On-prem ranges learned over FastConnect and VPN (from the DRG route table or your edge router)
  • Partner and other-cloud ranges reachable through the DRG
  • Ranges used by containers inside the VCN, such as OKE flannel pod CIDRs, Docker bridges (172.17.0.0/16) and VPN client pools
oci network drg-route-rule list --drg-route-table-id "$DRG_RT" --all \
  --query 'data[].{dest:destination, type:"route-type", attach:"next-hop-drg-attachment-id"}' --output table

Caution

An overlap with an on-prem or peered range doesn't fail at creation. The add succeeds, and then traffic to the overlapping range goes to the wrong place: local routes win inside the VCN, and the remote side may black-hole return traffic. Get the IPAM owner to sign off on the new block before you add it.

Fix

Option 1: the subnet can grow in place

If the space directly after the subnet is free and inside a VCN CIDR, you can expand it while keeping the same network address. For example, 10.20.4.0/24 can become 10.20.4.0/23 if 10.20.5.0/24 is unused.

oci network subnet update --subnet-id "$SUBNET" --cidr-block 10.20.4.0/23 --force
oci network subnet get --subnet-id "$SUBNET" --query 'data."lifecycle-state"'

The existing IPs, the gateway and the security lists all stay the same. This is the least disruptive option.

Option 2: add a second CIDR to the subnet

If the next block is taken, add a non-contiguous range to the same subnet:

oci network subnet add-ipv4-subnet-cidr --subnet-id "$SUBNET" --ipv4-cidr-block 10.20.40.0/24

Workloads keep the same subnet OCID, so instance pools, OKE node pools and LB configs don't need to change. This option means extra work on security rules: any CIDR-based rule that names the old subnet range doesn't cover the new one.

Option 3: the VCN itself is full

Add a VCN CIDR, then create subnets in it or expand into it:

oci network vcn add-vcn-cidr --vcn-id "$VCN" --cidr-block 10.21.0.0/16
oci network vcn get --vcn-id "$VCN" --query 'data.{state:"lifecycle-state", cidrs:"cidr-blocks"}'

The VCN is UPDATING while the change applies, and route table and subnet edits in it are blocked. Don't run this in the middle of another change on the same VCN, and pause Terraform pipelines that target it.

Use modify-vcn-cidr only to widen an existing block, for example 10.20.0.0/20 to 10.20.0.0/16. The new block has to contain every subnet and every address used in route rules:

oci network vcn modify-vcn-cidr --vcn-id "$VCN" \
  --original-cidr-block 10.20.0.0/20 --new-cidr-block 10.20.0.0/16

Make the new range reachable

A new address range isn't reachable until every path knows about it. Work through this list:

Path What to update
Security lists / NSGs CIDR-based rules that reference the old subnet or VCN range, in this VCN and in peered VCNs
DRG (hub-and-spoke) VCN attachments with route distribution import VCN CIDRs automatically. Static DRG route rules don't, so add them
Hub firewall / Network Firewall Address lists and policies that name spoke ranges. Hub VCN ingress route tables that send spoke ranges to the firewall
LPG peering The peer's route table needs a rule for the new CIDR through its LPG
On-prem Check that the new prefix is advertised over FastConnect/VPN BGP and accepted by on-prem filters, and update static VPN routes
DNS Reverse zones for the new range, and resolver endpoint access rules
Other services Database ACLs, Autonomous DB access control lists, Object Storage network sources, IAM request.networkSource policies, third-party allow-lists

Check from both ends with Network Path Analyzer, or with a test instance in the new range:

# From an instance in the new range
ping -c3 10.0.0.10          # on-prem host
traceroute -T -p 443 10.30.1.20  # peered VCN service

Warning

Route distribution through a DRG has a common gap. If the spoke attachment's export or the hub's import uses a statement that matches specific CIDRs, not "all attachments of type VCN", the new block won't propagate and on-prem never learns it. Check the DRG route table for the new prefix before declaring the change complete.

Rollback

  • A subnet CIDR you added can be removed with oci network subnet remove-ipv4-subnet-cidr --subnet-id "$SUBNET" --ipv4-cidr-block 10.20.40.0/24 only if no IPs are allocated from it. A subnet always keeps at least one CIDR.
  • A VCN CIDR can be removed with oci network vcn remove-vcn-cidr --vcn-id "$VCN" --cidr-block 10.21.0.0/16 only if no subnet uses it.
  • Subnet expansion is easiest to reverse while the new addresses are still unused. Once IPs are allocated from them, treat the expansion as permanent.

Prevent it next time

  • Alarm before the subnet is full. Run a daily job that counts private IPs per subnet against the usable size and alerts at 80%.
  • Size OKE pod subnets and LB subnets separately from node subnets. Pod networking uses addresses much faster.
  • Plan VCNs with headroom: allocate a /16 per VCN from a central IPAM plan even if you only build /20s now, so later expansion is a modify-vcn-cidr and not a renumbering project.
  • Keep CIDR-based security rules and DRG statements in Terraform variables that are built from the VCN's cidr_blocks, so new ranges flow through automatically.