Calculating and Implementing Subnets

Overview

Subnetting is the process of dividing a network into smaller network segments. Understanding subnetting is crucial for network administration and configuration in Linux systems.

Subnetting Basics

IP Address Structure

An IPv4 address consists of 4 octets (32 bits total):

192.168.1.10

Each octet can range from 0 to 255.

Subnet Mask

A subnet mask determines which part of an IP address is the network and which part is the host.

  • 255.255.255.0 - /24 network (254 usable hosts)
  • 255.255.0.0 - /16 network (65,534 usable hosts)
  • 255.255.255.128 - /25 network (126 usable hosts)

CIDR Notation

CIDR (Classless Inter-Domain Routing) uses a slash followed by the number of network bits:

Examples:
192.168.1.0/24 = 255.255.255.0
10.0.0.0/8 = 255.0.0.0
172.16.0.0/12 = 255.240.0.0

Linux Networking Commands

ip addr show

Display network interfaces and their IP addresses.

ip route show

Display routing table.

ifconfig

Older command to view/configure network interfaces (may need net-tools package).

Key Calculations

  • Network Address: First address in the subnet (all host bits = 0)
  • Broadcast Address: Last address in the subnet (all host bits = 1)
  • Usable Hosts: Total hosts - 2 (network & broadcast)
  • Formula: Usable hosts = 2^(32 - prefix) - 2

Subnet Calculator

Enter an IP address and CIDR prefix to calculate subnet information.

Network Address 192.168.1.0
Subnet Mask 255.255.255.0
Broadcast Address 192.168.1.255
First Usable IP 192.168.1.1
Last Usable IP 192.168.1.254
Total Hosts 256
Usable Hosts 254