LAB 7 ‐ CIDR and IP Subnetting with MXToolbox - DevWithNehaCloud/Oracle-Cloud-Infrastructure-wiki GitHub Wiki

CIDR and IP Subnetting Overview

1. What is CIDR?

CIDR (Classless Inter-Domain Routing) is a method used to create flexible groups of IP addresses. It replaced the old "Classful" system (Class A, B, C) to prevent IP address wastage.

A CIDR block looks like this: 192.168.1.0/24

IP Address: The starting point of the network.

Slash Notation ( / ): Represents the Subnet Mask, telling you how many bits are fixed for the network and how many are available for hosts.

CIDR Reference Table

CIDR Prefix Total IPs OCI Use Case
/16 65,536 Typical VCN Size
/24 256 Standard Subnet Size
/30 4 Point-to-point / FastConnect
/32 1 Individual Host IP

How to Calculate IPs

To find the number of addresses in a CIDR block, use the power of 2 formula. Since an IPv4 address has 32 bits, you subtract the prefix ($n$) from 32.

The Formula: $$2^{(32 - n)}$$

Examples:

  • /24 Prefix: $32 - 24 = 8$ bits for hosts. $2^8 = 256$ total addresses.
  • /16 Prefix: $32 - 16 = 16$ bits for hosts. $2^{16} = 65,536$ total addresses.

[!IMPORTANT] OCI Reserved IPs: In every OCI subnet, 3 IP addresses are reserved for networking overhead and cannot be assigned to your instances:

  1. The first IP address (Network address).
  2. The second IP address (Default Gateway).
  3. Third IP address (Reserved for OCI internal use).

Example: In a /24 subnet, you have 256 - 3 = 253 usable IP addresses.

Masking is a technique used to divide an IP address into two specific parts: the Network ID (the "locked" portion that identifies the network) and the Host ID (the "unlocked" portion available for assigning to devices like servers or databases).Example: Locking 24 Bits (192.168.1.0/24)When you apply a /24 mask, you are locking the first 24 bits. Here is how that looks in practice:

The Locked Part (Network ID): 192.168.1 (This part cannot change).

The Unlocked Part (Host ID): The remaining 8 bits are free for you to use.

Calculation of IPs:Total Bits in IPv4: 32 bits.Locked Bits: 24 bits.Available Host Bits: $32 - 24 = 8$ bits.The number of possible combinations you can create with 8 bits is calculated as:$$2^8 = 256 (total IP addresses)

Using a /24 CIDR block, we define an IP range from 192.168.1.0 to 192.168.1.255. However, not every IP in this range is available for compute instances.

2. What is Subnetting?

Subnetting is the process of breaking down a large CIDR block (like a VCN) into smaller, manageable pieces called Subnets. In OCI, you use subnets to isolate different tiers of your application (e.g., Web Subnet vs. Database Subnet).

Subnetworking Strategy for Application Isolation

In this module, I implemented Subnetting by dividing a parent network range into three distinct Sub-networks. This approach is crucial for organizing cloud resources and ensuring network security across different business units.

1. Subnet Allocation Overview

By partitioning the address space using a /16 mask, I have created dedicated environments for three major applications. This ensures each application operates in its own logical space.

Application Subnet (CIDR Block) Network Mask Logical Identity
Flipkart 10.0.0.0/16 /16 Subnet A
Amazon 10.1.0.0/16 /16 Subnet B
Swiggy 10.2.0.0/16 /16 Subnet C

2. Key Concepts Applied

  • Subnetting Logic: I utilized a /16 mask to create large sub-networks from a private IP pool (Class A). This allows for a hierarchical design where each application has a massive range of 65,536 IPs to grow without overlapping.
  • Logical Segmentation: Although these belong to the same private IP class, they function as independent sub-networks. This enables the implementation of specific Security Lists and Network Security Groups (NSGs) for each application.
  • Non-Overlapping Design: By changing the second octet (10.0, 10.1, 10.2), I have ensured that these networks can be connected via VCN Peering in the future without any IP address conflicts.

3. Implementation Benefits

  1. High Scalability: Each /16 subnet can be further divided into smaller /24 subnets for Web, App, and Database layers.
  2. Simplified Routing: Traffic management becomes easier as the IP range clearly identifies which application the traffic belongs to.
  3. Strict Isolation: A configuration change or security breach in the Swiggy subnet will not impact the Flipkart or Amazon environments.

MXToolbox for Network Troubleshooting

MXToolbox is an essential third-party tool for OCI Administrators to verify DNS, IP health, and Subnetting.

Key Features for Networking: Subnet Calculator: Helps you visualize the range of a CIDR block, including the broadcast address and mask.

DNS Lookup: Verifies if your Public IPs are correctly mapped to Domain Names.

Blacklist Check: Essential for Public IPs—ensure your assigned OCI Public IP isn't flagged for spam.

How to use the MXToolbox Subnet Calculator: Navigate to MXToolbox Subnet Calculator.

Enter your VCN or Subnet CIDR (e.g., 10.0.0.0/24).

Review the Output: It will provide the IP Range, Netmask, and CIDR notation to ensure your OCI configuration matches your plan.

CIDR & MXToolbox Integration Guide

IP Calculation Logic

CIDR Total IPs OCI Usable Formula
/16 65,536 65,533 2^(32-16)
/24 256 253 2^(32-24)

External Tools: MXToolbox

When designing OCI networks, use MXToolbox to validate your IP planning.

  • Tool: MXToolbox Subnet Calculator
  • Purpose: * Validate the start and end IP of a CIDR block.
    • Convert Subnet Masks (e.g., 255.255.255.0) to CIDR (/24).
    • Verify that your public-facing OCI resources are not on global blacklists.

Pro-Tip: Before applying a CIDR block to a production OCI VCN, always run it through a calculator to ensure you have enough host bits for future growth.