Sub topic 3
Variable-Length Subnet Masking and Route Selection
Assume you know IPv4 binary, CIDR prefix lengths, subnet masks, and how to calculate network and broadcast addresses. This chapter focuses on applying those calculations to uneven network designs and routing.
Variable-length subnet masking
Variable-length subnet masking (VLSM) assigns different prefix lengths within one address block. A larger group receives a shorter prefix, while a small link receives a longer prefix. Allocate the largest requirement first so each later subnet begins on a valid boundary.
For 192.168.1.0/24, these requirements fit without overlap:
- 100 hosts:
192.168.1.0/25 - 50 hosts:
192.168.1.128/26 - 20 hosts:
192.168.1.192/27 - 2 hosts:
192.168.1.224/30
A common error is allocating in the order requests arrive. Another is starting a subnet at an address that does not align with its block size.
Special prefixes and reserved ranges
A /31 has two addresses and is commonly used for point-to-point links. Under RFC 3021, both addresses can be used as endpoints, so there is no traditional network or broadcast address.
A /32 identifies one IPv4 address. It can represent a loopback, a host route, or a single route destination.
RFC 1918 private ranges are:
10.0.0.0/8172.16.0.0/12192.168.0.0/16
Private addresses are not routed directly across the public Internet. Network address translation or another gateway function is normally required.
Summarizing routes
Route summarization combines contiguous, aligned networks into one shorter prefix. For example, four /24 networks from 192.168.0.0 through 192.168.3.0 summarize as 192.168.0.0/22. The summary must cover exactly the intended range. Summarizing noncontiguous networks can send traffic toward the wrong destination.
Longest-prefix match in routing
When several routes match a destination, a router chooses the route with the longest prefix. This route has the most matching network bits and is therefore the most specific.
Checking your work with Python
Python’s ipaddress module verifies boundaries, host counts, and summaries.
import ipaddress
net = ipaddress.ip_network("192.168.1.0/24")
for subnet in net.subnets(new_prefix=26):
print(subnet, subnet.network_address, subnet.broadcast_address)
blocks = [
ipaddress.ip_network("192.168.0.0/24"),
ipaddress.ip_network("192.168.1.0/24"),
ipaddress.ip_network("192.168.2.0/24"),
ipaddress.ip_network("192.168.3.0/24"),
]
print(list(ipaddress.collapse_addresses(blocks)))Exercise
Which route wins for destination 192.168.1.42: 192.168.0.0/16 or 192.168.1.0/24?
Show answer
192.168.1.0/24 wins because it has the longer, more specific prefix.