A practical masterclass covering IPv4 architecture, Classful vs CIDR subnetting calculations, RFC 1918 private scopes, IPv6 essentials, and persistent static IP configuration on Ubuntu and RHEL.
An Internet Protocol (IP) address is a logical numerical label assigned to every device connected to a computer network that uses the Internet Protocol for communication. While physical MAC addresses identify hardware at the local Data Link layer (Layer 2), IP addresses operate at the Network layer (Layer 3) to enable routing across interconnected LANs, WANs, and the worldwide Internet.
In production Linux environments, system administrators must understand binary subnetting to design network topology, calculate available host capacities, prevent address conflicts, and configure persistent network adapters across different Linux distributions like Ubuntu, Debian, Rocky Linux, and Red Hat Enterprise Linux.
An IPv4 address consists of 32 binary bits structured into four 8-bit groupings known as octets. In human-readable form, it is written in dotted-decimal notation:
Dotted Decimal: 192 . 168 . 1 . 100
Binary Octets: 11000000 . 10101000 . 00000001 . 01100100
Bit Length: [8 bits] . [8 bits] . [8 bits] . [8 bits] = 32 bits total ($2^{32} \approx 4.29\text{ billion addresses}$)
Every IP address is divided into two distinct logical portions:
In the original 1981 Internet specification (RFC 791), IPv4 addresses were divided into five rigid classes based on the value of their first octet:
| Class | Leading Bits | 1st Octet Range | Default Subnet Mask | CIDR Prefix | Max Networks | Usable Hosts Per Network |
|---|---|---|---|---|---|---|
| Class A | 0 |
1 – 126 | 255.0.0.0 | /8 | 126 | 16,777,214 |
| Class B | 10 |
128 – 191 | 255.255.0.0 | /16 | 16,384 | 65,534 |
| Class C | 110 |
192 – 223 | 255.255.255.0 | /24 | 2,097,152 | 254 |
| Class D | 1110 |
224 – 239 | N/A (Multicast) | N/A | N/A | Reserved for Multicast Groups |
| Class E | 1111 |
240 – 255 | N/A (Experimental) | N/A | N/A | Reserved for Research & Future Use |
What happened to 127.0.0.0/8? The entire
127.0.0.0to127.255.255.255range is reserved for the local loopback interface (lo). Any packet sent to127.0.0.1(localhost) is intercepted internally by the Linux kernel without hitting the physical network wire.
Classful boundaries caused massive address waste (e.g., an enterprise needing 300 IP addresses was forced to take a Class B block with 65,534 IPs, wasting over 65,000 addresses). In 1993, CIDR (RFC 1519) replaced classful boundaries with variable-length prefix notation (e.g. /24, /27, /29), allowing organizations to allocate exact subnet sizes matching their actual host needs.
The subnet mask tells the Linux kernel which bits belong to the network and which bits identify the host. For any prefix length $P$, the number of usable host addresses is calculated using the formula:
We always subtract 2 because the first address is the Network ID and the last address is the Directed Broadcast Address.
| CIDR Prefix | Subnet Mask | Total Addresses | Usable Hosts | Common Production Use Case |
|---|---|---|---|---|
/30 |
255.255.255.252 | 4 | 2 | Point-to-Point router links (WAN interconnects) |
/29 |
255.255.255.248 | 8 | 6 | Small public IP blocks (ISP gateways, HA firewalls) |
/28 |
255.255.255.240 | 16 | 14 | DMZ server subnet, staging database cluster |
/27 |
255.255.255.224 | 32 | 30 | Departmental subnet, small office branch |
/26 |
255.255.255.192 | 64 | 62 | Medium cloud VPC subnet (AWS/GCP public tier) |
/25 |
255.255.255.128 | 128 | 126 | Half Class C subnet |
/24 |
255.255.255.0 | 256 | 254 | Standard corporate LAN, home Wi-Fi network |
/23 |
255.255.254.0 | 512 | 510 | Supernet combining two /24 blocks |
/16 |
255.255.0.0 | 65,536 | 65,534 | Large corporate campus, cloud VPC network |
/8 |
255.0.0.0 | 16,777,216 | 16,777,214 | Enterprise global private backbone (10.0.0.0/8) |
192.168.10.0192.168.10.1 (usually Default Gateway)192.168.10.62192.168.10.63Because the 4.3 billion IPv4 address pool was quickly exhausted, the Internet Engineering Task Force (IETF) created RFC 1918, designating three private address blocks that are never routed on the public Internet:
10.0.0.0 to 10.255.255.255 (1 Class A network, 16,777,214 hosts). Used heavily in large data centers and AWS/Azure/GCP cloud VPCs.172.16.0.0 to 172.31.255.255 (16 contiguous Class B networks, 1,048,574 hosts). Used by Docker bridge networks (default 172.17.0.0/16).192.168.0.0 to 192.168.255.255 (256 contiguous Class C networks, 65,534 hosts). The standard default in home routers and small offices.Private IP hosts communicate with the public Internet through Network Address Translation (NAT / Masquerading) performed by Linux routers via iptables or nftables.
To eliminate address exhaustion permanently, IPv6 provides 128 bits of address space ($2^{128} \approx 3.4 \times 10^{38}$ unique addresses). Written in 8 groups of four hexadecimal digits separated by colons:
2001:0db8:85a3:0000:0000:8a2e:0370:73342001:db8:85a3::8a2e:370:7334
fe80::/10 (automatically generated for internal communication on a single switch/link).::1 (equivalent to IPv4 127.0.0.1).2000::/3 (globally routable public addresses).Ubuntu utilizes Netplan, which reads declarative YAML configuration files stored in /etc/netplan/:
# 1. Locate the netplan configuration file
ls /etc/netplan/
# Usually: 01-netcfg.yaml or 50-cloud-init.yaml
# 2. Edit the netplan configuration with sudo
sudo nano /etc/netplan/01-netcfg.yaml
Configure the static IP with exact indentation (Netplan strictly forbids tab characters):
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses:
- 192.168.1.150/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 1.1.1.1
# 3. Test and apply netplan configuration safely
sudo netplan try
# Or apply directly:
sudo netplan apply
Enterprise Red Hat families manage persistent network configurations via NetworkManager:
# 1. Identify active connection name
nmcli con show
# 2. Modify connection eth0 to static IP, gateway, and DNS
sudo nmcli con mod "eth0" ipv4.addresses 192.168.1.150/24
sudo nmcli con mod "eth0" ipv4.gateway 192.168.1.1
sudo nmcli con mod "eth0" ipv4.dns "8.8.8.8 1.1.1.1"
sudo nmcli con mod "eth0" ipv4.method manual
# 3. Reload and reactivate the connection profile
sudo nmcli con up "eth0"
# 4. Alternatively, use the interactive terminal UI
sudo nmtui
The ipcalc utility eliminates calculation errors when planning subnets:
# Install ipcalc on Debian/Ubuntu or RHEL
sudo apt install ipcalc -y # Debian/Ubuntu
sudo dnf install ipcalc -y # RHEL/Rocky
# Calculate complete subnet details for 172.16.50.0/27
ipcalc 172.16.50.0/27
Example Output:
Address: 172.16.50.0 10101100.00010000.00110010.000 00000
Netmask: 255.255.255.224 = 27 11111111.11111111.11111111.111 00000
Wildcard: 0.0.0.31 00000000.00000000.00000000.000 11111
=>
Network: 172.16.50.0/27 10101100.00010000.00110010.000 00000
HostMin: 172.16.50.1 10101100.00010000.00110010.000 00001
HostMax: 172.16.50.30 10101100.00010000.00110010.000 11110
Broadcast: 172.16.50.31 10101100.00010000.00110010.000 11111
Hosts/Net: 30 (Class B)
In Linux, a single physical interface can host multiple IP addresses simultaneously:
# Add a secondary virtual IP to eth0
sudo ip addr add 192.168.1.200/24 dev eth0
# Verify both IP addresses are active
ip -br a show dev eth0
# Remove the secondary IP
sudo ip addr del 192.168.1.200/24 dev eth0
192.168.1.128 and spans 128 addresses (128 to 255). Therefore, the Broadcast Address is 192.168.1.255, and the usable host range is 192.168.1.129 through 192.168.1.254.
dhclient or systemd-networkd; the lease must be renewed periodically and may change.
169.254.0.0/16 range (Automatic Private IP Addressing). This allows local ad-hoc communication between devices on the same switch without internet connectivity.
iproute2 suite (such as ip addr add or ip route add) directly modify volatile kernel routing and interface tables in RAM. Upon reboot, the kernel reinitializes network state from persistent configuration files on disk (such as /etc/netplan/*.yaml in Ubuntu or NetworkManager keyfiles in /etc/NetworkManager/system-connections/ on RHEL).