IP Subnetting
Subnetting divides a network into smaller, manageable segments for better organization and security.
CIDR Notation
192.168.1.0/24
/24 = 24 network bits = 255.255.255.0 subnet mask
= 8 host bits = 256 addresses (254 usable)Subnet Mask Reference
| CIDR | Subnet Mask | Hosts | Networks |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,214 | 1 |
| /16 | 255.255.0.0 | 65,534 | 256 |
| /24 | 255.255.255.0 | 254 | 65,536 |
| /25 | 255.255.255.128 | 126 | 131,072 |
| /26 | 255.255.255.192 | 62 | 262,144 |
| /27 | 255.255.255.224 | 30 | 524,288 |
| /28 | 255.255.255.240 | 14 | 1,048,576 |
| /29 | 255.255.255.248 | 6 | 2,097,152 |
| /30 | 255.255.255.252 | 2 | 4,194,304 |
| /32 | 255.255.255.255 | 1 | - |
Calculating Subnets
Example: Divide 192.168.1.0/24 into 4 subnets
Original: 192.168.1.0/24 (256 addresses)
Need: 4 subnets
Solution: Borrow 2 bits (2^2 = 4)
New mask: /26
Subnet 1: 192.168.1.0/26 (1-62)
Subnet 2: 192.168.1.64/26 (65-126)
Subnet 3: 192.168.1.128/26 (129-190)
Subnet 4: 192.168.1.192/26 (193-254)Private IP Ranges
Class A: 10.0.0.0/8 (10.0.0.0 - 10.255.255.255)
Class B: 172.16.0.0/12 (172.16.0.0 - 172.31.255.255)
Class C: 192.168.0.0/16 (192.168.0.0 - 192.168.255.255)VLSM (Variable Length Subnet Masking)
Allocate different subnet sizes based on need:
Network: 10.0.0.0/24
Dept A (100 hosts): 10.0.0.0/25 (128 addresses)
Dept B (50 hosts): 10.0.0.128/26 (64 addresses)
Dept C (20 hosts): 10.0.0.192/27 (32 addresses)
Links (2 hosts): 10.0.0.224/30 (4 addresses each)Linux Network Configuration
# View current configuration
ip addr show
# Add IP address
sudo ip addr add 192.168.1.100/24 dev eth0
# Calculate subnet info
ipcalc 192.168.1.0/24
# Check routing table
ip route showSubnetting Formula
Hosts per subnet = 2^(32 - CIDR) - 2
Subnets available = 2^(CIDR - original_CIDR)
Example /26 from /24:
Hosts = 2^(32-26) - 2 = 64 - 2 = 62
Subnets = 2^(26-24) = 4Best Practices
- Plan ahead - Account for future growth
- Document everything - IP allocation spreadsheet
- Use VLSM - Efficient address utilization
- Reserve addresses - For network devices
- Separate by function - Servers, users, management
- subnetting
- cidr
- ip addressing
- network design
- subnet mask
- vlsm