Back to Blog
Building a Secure VCN in OCI: A Complete Guide for Small Businesses

Building a Secure VCN in OCI: A Complete Guide for Small Businesses

   Mariusz Antonik    Oracle Cloud (OCI)    3 min read    5 views

1. Introduction

In this guide, I’ll take you through a deep technical walkthrough of building a Virtual Cloud Network (VCN) in Oracle Cloud Infrastructure. If you’re a small business owner, developer, or network engineer, this is the foundation of everything you will ever deploy in OCI.

A poorly designed VCN creates ongoing problems—slow services, blocked traffic, security exposures, and troubleshooting nightmares. A well-designed VCN gives you speed, visibility, and a rock-solid security posture.


2. What Problem This Solves

Most new OCI tenants suffer from:

  • VCN scattered across random subnets

  • Missing route table entries

  • Wide-open 0.0.0.0/0 firewall rules

  • Unnecessary exposure of compute instances

  • No compartment or regional structure

This post solves exactly that—a clean, secure, production-ready VCN setup.


3. Step-by-Step Guide

Step 1 — Create the VCN

OCI Console → Networking → Virtual Cloud Networks → Create VCN

Recommended CIDR:

 
10.0.0.0/16

CLI

 
oci network vcn create \ --cidr-block 10.0.0.0/16 \ --compartment-id <compartment_ocid> \ --display-name prod-vcn

Step 2 — Create Subnets

Recommended structure:

Subnet CIDR Type Purpose
public-lb 10.0.10.0/24 Public Load balancers
app-private 10.0.20.0/24 Private App servers
db-private 10.0.30.0/24 Private Databases

CLI

 
oci network subnet create \ --vcn-id <vcn_ocid> \ --cidr-block 10.0.20.0/24 \ --display-name app-private \ --prohibit-public-ip-on-vnic true \ --compartment-id <compartment_ocid>

Step 3 — Create Gateways

Internet Gateway

 
oci network internet-gateway create \ --vcn-id <vcn_ocid> \ --is-enabled true \ --display-name igw-prod

NAT Gateway

 
oci network nat-gateway create \ --vcn-id <vcn_ocid> \ --display-name nat-prod

Service Gateway (important for DB + Object Storage)

 
oci network service-gateway create \ --vcn-id <vcn_ocid> \ --services '[{"serviceId":"all-gru-services"}]' \ --display-name sgw-prod

Step 4 — Configure Route Tables

App subnet route:

 
0.0.0.0/0 → NAT Gateway objectstorage → Service Gateway

Step 5 — Secure Network with Security Lists

Example security list:

 
# Allow SSH only from your home/work IP oci network security-list update \ --security-list-id <sl_id> \ --egress-security-rules '[{"protocol":"all","destination":"0.0.0.0/0"}]' \ --ingress-security-rules '[ {"protocol":"6","source":"203.0.113.0/24","tcpOptions":{"destinationPortRange":{"min":22,"max":22}}}, {"protocol":"6","source":"10.0.0.0/16","tcpOptions":{"destinationPortRange":{"min":80,"max":80}}} ]'

4. Architecture Diagram

 
┌──────────────────────────────┐ │ Oracle Region │ └──────────────┬───────────────┘ VCN (10.0.0.0/16) ┌──────────────────────────────────────────────────────────────┐ │ Public Subnet (10.0.10.0/24) │ │ ┌───────────────┐ │ │ │ LB (Public) │───Internet Gateway │ │ └───────────────┘ │ ├──────────────────────────────────────────────────────────────┤ │ App Private Subnet (10.0.20.0/24) │ │ ┌───────────────┐ │ │ │ Compute Nodes │───NAT Gateway │ │ └───────────────┘ │ ├──────────────────────────────────────────────────────────────┤ │ DB Private Subnet (10.0.30.0/24) │ │ ┌───────────────┐ │ │ │ MySQL/ATP │───Service Gateway → Object Storage │ │ └───────────────┘ │ └──────────────────────────────────────────────────────────────┘

5. Best Practices

  • Never assign public IPs to compute unless absolutely required

  • Prefer NAT Gateway for outbound traffic

  • Use network security groups instead of security lists for large deployments

  • Create dedicated compartments per environment: prod, qa, dev

  • Always use private subnets for databases

  • Enable VCN Flow Logs for troubleshooting


6. Common Errors / Troubleshooting

Error Cause Fix
Cannot SSH to compute Public subnet missing Move instance or add public IP
Database cannot reach Object Storage No Service Gateway route Add route entry
App cannot reach DB Security list blocking port Add TCP port 3306/1521 rule
Server has no internet Missing NAT route Update route table

7. Summary

You now have a complete, secure, and scalable VCN design ready for production or Always Free Tier environments. This is the backbone of every OCI deployment—compute, databases, load balancers, OKE, and more.


Since this is a networking-related post, CTA = Lead Magnet

👉 Download my free guide:
7 OCI Networking Mistakes to Avoid

https://dmcloudarchitect.com/c/7_oci_mistakes_to_avoid.html

Tags: #OCI