IPv4 & Subnets
Most important commands to remember
ip -4 address— inspect IPv4 addresses and prefixes.ip -4 route— inspect routes or ask which route Linux would use.
Commands and flags
These commands appear in the short example below.
| Command | Meaning |
|---|---|
ip -4 -br address show |
Show a brief address summary. -4 selects IPv4; -br means brief. |
ip -4 route show |
Show the main IPv4 routing table. |
ip -4 route get 192.0.2.1 |
Ask Linux which route it would select for this destination. It does not send a packet. |
192.0.2.1 belongs to a documentation range. Here it is only an input to a local route lookup, not a server we expect to contact.
The concepts that matter
1. An IPv4 address identifies an IP endpoint
An IPv4 address contains 32 bits, usually written as four decimal numbers from 0 to 255, such as 192.0.2.10. Each number represents eight bits.
An interface can have an IPv4 address and a network prefix. One machine can have several interfaces and addresses, so an address is not a permanent identity for the whole machine.
2. The prefix defines a subnet’s address boundary
In 192.0.2.10/24, /24 means the first 24 bits describe the network prefix. The remaining eight bits distinguish addresses within that subnet. This notation is called CIDR.
The subnet is 192.0.2.0/24. Addresses such as 192.0.2.10 and 192.0.2.20 share it; 192.0.3.20 does not. The equivalent subnet mask is 255.255.255.0.
A larger prefix length means a smaller address range. A /24 contains 256 addresses, while a /30 contains four. In ordinary IPv4 subnets like these, network and broadcast addresses are not assigned to hosts, leaving 254 and two respectively. Special cases such as /31 and /32 use different rules.
These addresses illustrate the boundaries; they are not measurements from your machine.
3. Local delivery and routed delivery use different next hops
On a typical Ethernet subnet, assigning an address and prefix also creates a connected route. A destination covered by that route can be reached directly on the link. ARP resolves its MAC address.
For a destination reached through a gateway, the host sends the frame to that router’s MAC instead. The IP packet still carries the final destination address. The gateway is the next step, not a replacement destination.
A prefix helps define the connected network, but the actual routing table decides where traffic goes. More specific routes can change the decision.
4. Routes tell Linux where to send packets
A route associates a destination prefix with an interface and, when needed, a next-hop gateway. Among matching prefixes, the most specific one—the longest prefix—wins in an ordinary table lookup.
A default route covers destinations without a more specific match. It is a fallback, not a guarantee of internet access. Without a matching route, Linux can report that the network is unreachable before sending anything.
A correct-looking route also does not prove the gateway, return path, or application works. Route selection and successful communication are separate observations.
One small example
Optional: run these commands in a Linux terminal with iproute2 installed. No administrator access is needed:
ip -4 -br address show
ip -4 route show
ip -4 route get 192.0.2.1
First, find an interface address and its /PREFIX. In the route table, look for the corresponding connected network and any default entry. A connected route commonly shows proto kernel (created by the kernel) and scope link (direct link delivery).
Read dev as the outgoing interface, via as a gateway, and src as the chosen source address. The final lookup applies the routing rules to one destination; its interface or gateway may differ from what you expected.
Interface names, prefixes, and routes vary. No IPv4 address or a “Network is unreachable” result can be valid for a machine without suitable IPv4 configuration. This example changes nothing and tests no destination’s reachability, so no cleanup is needed.
Keep this idea: the address identifies an endpoint, the prefix defines a network range, and the route selects the next hop.