Routers, Routes, Subnets, and Netmasks
3,532 Total views across this article’s versions; includes the historical baseline where available.
A critical component of managing routes is understanding netmasks. Hosts as well as routers use address prefixes to describe local networks and route destinations. For IPv4, a contiguous netmask identifies the network bits, leaving the remaining bits to vary within that subnet.
Routers and Routes
Network routers forward IP packets between networks. Their routing information can come from interface configuration, static routes, or routing protocols. An administrator defines the intended topology and policy; dynamic discovery does not remove that responsibility.
Most ordinary IP traffic is unicast, addressed to one destination. IPv4 broadcast addresses instead reach hosts on the relevant broadcast network. Do not assume routers forward broadcasts like unicast: RFC 2644 requires directed-broadcast forwarding to be disabled by default. Routing protocols can exchange reachability information between routers, while static routes are configured explicitly.
Subnets
A subnet is an address block within a larger network. A host can have multiple interfaces and addresses. A network prefix groups destinations for routing; it is not an address reserved for conversations between routers. Hosts also use subnet information when deciding whether a destination is on-link or requires a gateway, as described in RFC 1122.
One prefix route can cover many addresses instead of listing each host separately. A LAN connects devices in a local area; a WAN connects networks over a wider area. These terms describe network scope, not a rule that a WAN excludes the Internet or that every LAN device has a direct physical cable to every other device.
Divide and Conquer
IPv4 has 2^32 possible address values, about 4.3 billion; not all are available for public unicast use. Each address remains 32 bits whether a host or a router handles it. Dotted-decimal notation presents those bits as four octets, each from 0 to 255.
A route can be described by a 32-bit network address plus a separate 32-bit netmask, or by an address and prefix length such as 192.0.2.0/24. Putting an address and mask side by side does not create a 64-bit IPv4 address. The routing prefix identifies the network bits and their length; see RFC 4632.
Subnetworks and Netmasks
Within the selected routing table, the longest matching destination prefix is the most specific eligible route. For example, a /32 host route wins over a matching /24 network route. This compares prefix lengths, not command lengths or the position of a route in a listing. Policy-rule priority is a separate decision that selects which table to consult.
Each router makes its own next-hop decision using its local routing information. A packet may follow several default or aggregate routes before reaching its destination network; the chosen prefix does not have to become more specific at every hop.
Genmask
Genmask labels the destination netmask in the legacy route(8) display. The command comes from net-tools; it is not an iptables command or an iproute2 process.
For the columns in the legacy display, see route and netstat.
Endnotes
[1] Brown, Martin A. 14 March 2007. Guide to IP Layer Network Administration with Linux. Version 0.4.5. Chapter 1. Basic IP Connectivity. http://linux-ip.net/html/index.html.