hexdefender
Email
  • Introduction to Linux
    • Overview
    • Linux Kernel
    • Linux Distros
    • Introduction to Kali Linux
    • Install Kali on VirtualBox
    • Install Kali on AWS
  • Linux Commands
    • Linux File Systems
    • Basic File and Directory commands
    • File Permissions and Ownerships
    • System Commands in Linux
    • Text Processing Commands in Linux
    • Linux Archive Utility
    • Package Management in Kali Linux
    • Networking Commands
    • Disk Utility Tools
    • Linux List of CLI Command lookup
    • Linux CLI Cheatsheet
    • Assignment
  • Networking Essentials
    • Overview
    • Networking Protocols
    • IP Addressing & Subnetting
    • DNS and DNS Security
    • Network Devices and Architecture
    • VPNs and Secure Tunnels
    • Network Address Translation (NAT) & Port Forwarding
    • Wireless Networks & Protocols
    • Cloud Networking & Security
    • Common Network Tools
  • Bash Scripting
    • Fundamentals of Bash
    • Variables, Branching and Loops
    • System Variables in Bash
    • Functions and Error Handling in Bash Scripts
    • File Handling and Text Processing
    • 5 Useful Bash Scripts for Everyday Tasks
    • Useful Assignments
  • Fundamentals of Cybersecurity
    • Introduction to Cybersecurity
    • Importance of Cybersecurity
    • Important Cybersecurity Frameworks
    • Cybersecurity Roles and Career Options
  • Penetration Testing
    • Reconnaissance and Footprinting
    • Exploitation Techniques
      • Introduction
      • Service Enumeration
      • Password Attacks
      • Exploit Discovery
      • The Art of Exploitation
      • The Pentester's guide to Metasploit
    • Post Exploitation - Malware & Escalation
  • Web Application Security
    • Common Web Vulnerabilities
    • OWASP Top 10
    • SQL Injections
    • Cross Site Scripting Attacks
    • Web Application Firewalls
    • Secure Coding Practices
  • Cryptography
    • Basic concepts of cryptography
    • Examples of Asymetric & Hashing functions
    • Public Key Infrastructure
    • Digital Signatures
    • Symmetric and Asymmetric Encryption
  • Social Engineering
    • Introduction to Social Engineering
    • Mitigation Strategies for Social Engineering
  • Digital Forensics
    • Digital Forensics Basics
    • Forensics Tools and Techniques
    • Reverse Engineering Fundamentals
    • Malware Analysis
Powered by GitBook
On this page
  1. Networking Essentials

IP Addressing & Subnetting



1. Introduction to IP Addressing

IP Addressing is a fundamental concept in networking, used to identify devices on a network. Every device that communicates on a network is assigned an IP (Internet Protocol) address, which is either in IPv4 or IPv6 format.

  • IPv4: A 32-bit address represented in decimal form.

  • IPv6: A 128-bit address designed to replace IPv4 due to the shortage of IPv4 addresses.

2. IPv4 Address Structure

IPv4 Addressing: IPv4 addresses are 32-bit numbers, written as four decimal numbers separated by dots (called "dotted decimal notation"). Each decimal number represents an 8-bit section (or octet) of the 32-bit address.

Example of an IPv4 address:

192.168.1.10

Binary Representation: Each octet in an IPv4 address can be represented as 8 bits in binary.

Example:

192.168.1.10 = 11000000.10101000.00000001.00001010

Each of these binary values represents part of the address, where:

  • 192 = 11000000

  • 168 = 10101000

  • 1 = 00000001

  • 10 = 00001010


3. Class-Based IP Addressing

Classful Addressing divides IP addresses into five classes (A, B, C, D, and E), based on their leading bits and ranges. This was the earlier method of assigning IP addresses.

IP Address Classes

Class

Leading Bits

Range

Default Subnet Mask

Use

A

0

0.0.0.0 to 127.255.255.255

255.0.0.0

Large networks

B

10

128.0.0.0 to 191.255.255.255

255.255.0.0

Medium-sized networks

C

110

192.0.0.0 to 223.255.255.255

255.255.255.0

Small networks

D

1110

224.0.0.0 to 239.255.255.255

-

Multicasting

E

1111

240.0.0.0 to 255.255.255.255

-

Experimental and reserved use

  • Class A: For large organizations and ISPs. E.g., 10.0.0.0/8 (Private range).

  • Class B: For medium-sized organizations. E.g., 172.16.0.0/12 (Private range).

  • Class C: For small networks, commonly used for home networks. E.g., 192.168.0.0/16 (Private range).

  • Class D: Reserved for multicast addresses.

  • Class E: Reserved for experimental purposes.

Private vs. Public Addresses

  • Public IP addresses: Globally unique and routable on the internet.

  • Private IP addresses: Not routable on the internet and used within private networks.

Private IP ranges (for Class A, B, and C):

  • Class A: 10.0.0.0 to 10.255.255.255

  • Class B: 172.16.0.0 to 172.31.255.255

  • Class C: 192.168.0.0 to 192.168.255.255

4. CIDR (Classless Inter-Domain Routing)



What is CIDR?

CIDR (Classless Inter-Domain Routing) was introduced in 1993 as a replacement for the older classful networking system (Class A, B, C, etc.). CIDR allows for more flexible and efficient use of IP addresses by removing the fixed boundaries of class-based IP addresses. Instead of rigid network classes, CIDR enables networks to be split (subnetted) or grouped (supernetted) as needed, improving IP address allocation.


Why was CIDR Introduced?

  1. IPv4 Address Exhaustion: The Internet grew exponentially, and the rigid class-based system couldn't allocate IP addresses efficiently. Large blocks of addresses were being wasted (for example, an organization might be given a whole Class B address block with 65,536 IP addresses, even though it only needed 1,000). This led to a rapid depletion of available IPv4 addresses.

  2. Improved Routing Efficiency: Without CIDR, routers had to store vast numbers of routing table entries for every network. CIDR aggregates multiple IP addresses into a single routing entry (route aggregation or supernetting), simplifying routing decisions.


CIDR Notation Structure

A CIDR IP address is written as:

<IP Address>/<Subnet Mask Prefix>

Where:

  • IP Address: The starting IP address of the network.

  • Subnet Mask Prefix: The number of bits used for the network portion, represented after a forward slash.

For example:

192.168.1.0/24
  • 192.168.1.0: This is the base (or starting) address of the network.

  • /24: This is the CIDR prefix that tells us that the first 24 bits are reserved for the network, and the remaining 8 bits can be used for host addresses.

How CIDR Works

CIDR allows for more fine-grained control over the size of your network by adjusting the number of bits in the subnet mask (prefix length). The more bits you dedicate to the network portion, the fewer bits you have available for hosts (and vice versa).

  • Network Portion: The part of the IP address that identifies the network.

  • Host Portion: The part of the IP address that identifies specific devices (hosts) within that network.

CIDR Notation and Subnet Mask Relationship

In the traditional class-based system:

  • Class A used a subnet mask of 255.0.0.0 or /8 (8 bits for network).

  • Class B used a subnet mask of 255.255.0.0 or /16 (16 bits for network).

  • Class C used a subnet mask of 255.255.255.0 or /24 (24 bits for network).

With CIDR, we can use any number of bits for the network portion, giving much more flexibility.

Subnet Masks in CIDR

The subnet mask defines how many bits are used for the network portion versus the host portion. A subnet mask is a 32-bit binary number where the network bits are set to 1 and the host bits are set to 0.

For example:

/8  = 255.0.0.0      = 11111111.00000000.00000000.00000000
/16 = 255.255.0.0    = 11111111.11111111.00000000.00000000
/24 = 255.255.255.0  = 11111111.11111111.11111111.00000000
/30 = 255.255.255.252 = 11111111.11111111.11111111.11111100

CIDR Subnetting in Detail

Let’s take a network 192.168.1.0/24 and subnet it further using CIDR notation:

  • Original Network: Network: 192.168.1.0 Subnet Mask: /24 (255.255.255.0) This means the first 24 bits are for the network, and the remaining 8 bits are for hosts.

Subnetting the /24 Network into Smaller Networks

We can further divide the /24 network by adjusting the subnet mask. Let’s divide it into 4 subnets. To do this, we need to borrow 2 bits from the host portion.

  1. Calculate New Subnet Mask: Borrowing 2 bits means the network portion will now have 26 bits (24 + 2 = 26), resulting in a new subnet mask of /26.

    Binary representation of /26: 11111111.11111111.11111111.11000000 = 255.255.255.192

  2. Determine the Number of Hosts per Subnet: The remaining bits for hosts are 32 - 26 = 6. With 6 bits, we can have:

    • 2^6 = 64 addresses (but 2 are reserved: 1 for the network address and 1 for the broadcast address).

    • Usable hosts per subnet = 64 - 2 = 62.

  3. List the Subnets: Let’s divide 192.168.1.0/24 into four /26 subnets:

    • Subnet 1: Network Address: 192.168.1.0/26 Range: 192.168.1.1 to 192.168.1.62 Broadcast Address: 192.168.1.63

    • Subnet 2: Network Address: 192.168.1.64/26 Range: 192.168.1.65 to 192.168.1.126 Broadcast Address: 192.168.1.127

    • Subnet 3: Network Address: 192.168.1.128/26 Range: 192.168.1.129 to 192.168.1.190 Broadcast Address: 192.168.1.191

    • Subnet 4: Network Address: 192.168.1.192/26 Range: 192.168.1.193 to 192.168.1.254 Broadcast Address: 192.168.1.255

CIDR Supernetting

CIDR also allows for supernetting, which is the process of combining multiple smaller networks into one larger network. This is done by reducing the number of bits used for the network portion.

For example, if you want to combine two /24 networks, 192.168.1.0/24 and 192.168.2.0/24, into one larger network, you would:

  1. Look at the first 23 bits instead of 24 bits, resulting in a network like 192.168.0.0/23.

  2. This covers both 192.168.1.0 and 192.168.2.0 networks in one, creating a larger network with more IP addresses.

CIDR Examples

Let’s walk through more examples for clarity:

  1. Example 1: Subnetting a /16 Network

    Given network: 172.16.0.0/16. You want to create subnets with a maximum of 254 hosts each.

    • To do this, you need a subnet mask of /24 (which allows for 256 IP addresses per subnet, but 254 usable addresses).

    Resulting subnets:

    • 172.16.0.0/24: 254 hosts (172.16.0.1 - 172.16.0.254)

    • 172.16.1.0/24: 254 hosts (172.16.1.1 - 172.16.1.254)

    • And so on...

  2. Example 2: Supernetting

    You have two networks, 192.168.10.0/24 and 192.168.11.0/24, and you want to supernet them into one larger network.

    • The supernet would be 192.168.10.0/23, which combines both /24 networks.


Benefits of CIDR

  • More Efficient Address Allocation: CIDR allows networks of various sizes to be allocated IP address space without the wasteful fixed blocks of classful addressing.

  • Reduces Routing Table Size: CIDR enables route aggregation, reducing the number of routes that routers need to store and process.

  • Enables Both Subnetting and Supernetting: CIDR can be used to either break down larger networks into smaller subnets or combine smaller networks into larger supernets.

Subnet Calculators and Tools:

  1. IP Subnet Calculator by SolarWinds: This tool is one of the most user-friendly subnet calculators, perfect for calculating subnets, CIDR ranges, and IP address allocation.

  2. Subnet Calculator: Another excellent online tool that lets you input CIDR notation and quickly get detailed network ranges, subnet masks, and host ranges.

CIDR and IP Address Exhaustion Resources:

  1. IETF RFC 1519 – CIDR: An Address Assignment and Aggregation Strategy For a more technical deep dive, you can read the original specification of CIDR as proposed by the Internet Engineering Task Force (IETF).

  2. IANA IPv4 Address Space Allocation: The Internet Assigned Numbers Authority (IANA) manages the global allocation of IP addresses. This resource provides up-to-date information on IPv4 address exhaustion and allocation policies.

PreviousNetworking ProtocolsNextDNS and DNS Security

Last updated 8 months ago

SolarWinds Subnet Calculator
Subnet Calculator
RFC 1519
IANA IPv4 Allocation