Table of Contents
Understanding IP Addresses
In this chapter we focus on how IP addressing works on Linux systems: what an IP address looks like, how it’s structured, and the key concepts you need when configuring or troubleshooting network interfaces.
This chapter assumes you already know in general what a network and an IP-based network are from the parent “Networking Fundamentals” chapter.
IPv4 vs IPv6 (High-Level View)
Two main versions are in use:
- IPv4
- Uses 32-bit addresses.
- Written as four decimal numbers separated by dots, e.g.
192.168.1.10. - Supports about $2^{32} \approx 4.3$ billion addresses (many reserved).
- IPv6
- Uses 128-bit addresses.
- Written as eight groups of hexadecimal numbers separated by colons, e.g.
2001:db8::1. - Supports a vastly larger address space.
Most systems today use both; you’ll often see IPv4 for local networks and IPv6 increasingly used on the internet and modern ISPs.
IPv4 Address Structure
An IPv4 address is made of two logical parts:
- Network portion – identifies the network.
- Host portion – identifies the specific device (host) on that network.
Together with a subnet mask or prefix length, the system can tell which part is network and which part is host.
Example (CIDR form):
192.168.1.10/24
Here /24 is the prefix length: the first 24 bits are the network portion.
Subnet Masks and Prefix Lengths
A subnet mask is also a 32-bit number, often written in dotted decimal:
- Example:
255.255.255.0
This corresponds to prefix length /24 because:
- Binary of
255is11111111 - So
255.255.255.0is 24 ones followed by 8 zeros: - Network bits: 24
- Host bits: 8
Modern notation tends to use prefix length (CIDR):
10.0.0.0/8→ subnet mask255.0.0.0172.16.0.0/16→ subnet mask255.255.0.0192.168.1.0/24→ subnet mask255.255.255.0
Both notations describe the same thing: how many bits are used for the network.
Network, Host, and Broadcast Addresses
For any IPv4 subnet, we can derive three important quantities from the IP address and prefix length.
Given:
- Network address: all host bits set to 0.
- Broadcast address: all host bits set to 1.
- Usable host range: addresses between network and broadcast (when such a range exists).
Example: 192.168.1.0/24
- Prefix length:
/24→ 8 host bits (since 32 - 24 = 8). - Network address:
192.168.1.0 - Broadcast address:
192.168.1.255 - Usable hosts:
192.168.1.1to192.168.1.254 - Number of usable hosts: $2^{8} - 2 = 254$
Example: 10.0.0.0/30 (a very small subnet)
- Host bits: $32 - 30 = 2$
- Total addresses: $2^{2} = 4$
- Network:
10.0.0.0 - Broadcast:
10.0.0.3 - Usable hosts:
10.0.0.1,10.0.0.2
Linux tools like ip addr show will display the IP with CIDR notation; it’s up to you to understand what is network vs host and the usable range.
Private vs Public IPv4 Addresses
Some IPv4 ranges are private and not routable on the public internet. They’re meant for internal networks (home, office, datacenter):
10.0.0.0/8(10.x.x.x)172.16.0.0/12(172.16.x.x – 172.31.x.x)192.168.0.0/16(192.168.x.x)
Any IP outside those ranges (plus some special ranges) is generally public and can be routed on the internet.
In practice on Linux:
- Your home router will usually give your machine a private IP, like
192.168.1.42. - The router then uses NAT (network address translation) to share a single public IP among internal devices (NAT is covered elsewhere, but you’ll see symptoms of it when troubleshooting).
Loopback and Special IPv4 Addresses
Some special address ranges:
127.0.0.0/8– loopback addresses127.0.0.1is the standard loopback.- Used for referring to the local machine.
- Linux maps hostname
localhostto127.0.0.1. 0.0.0.0- Means “all IPv4 addresses on this machine” when used as a listen address (e.g. servers).
- Can also mean “no address” in some contexts.
- Link-local:
169.254.0.0/16 - Used when no DHCP address can be obtained.
- Linux may auto-assign one in some setups.
Basic IPv6 Address Structure
IPv6 uses 128-bit addresses, written in hexadecimal:
- Example:
2001:0db8:85a3:0000:0000:8a2e:0370:7334
Conventions to shorten IPv6:
- Remove leading zeros in each group:
2001:db8:85a3:0:0:8a2e:370:7334- Replace one consecutive sequence of
:0:groups with::: 2001:db8:85a3::8a2e:370:7334
You can only use :: once in an address.
IPv6 also uses prefix lengths:
- Example:
2001:db8::1/64 /64→ first 64 bits are the network portion.- Last 64 bits are typically for the host (interface identifier).
Common IPv6 Types
A few you’ll often see on Linux:
- Global unicast (public): like
2001:db8::/32in examples, or your ISP-assigned prefix. - Link-local:
fe80::/10 - Automatically assigned to interfaces.
- Used for communication on the local link.
- Usually written like
fe80::abcd:ef01:2345:6789%eth0(with interface name). - Loopback:
::1 - IPv6 equivalent of
127.0.0.1.
The concept of network vs host portions is similar to IPv4 but with larger sizes and different addressing rules.
Interfaces, Addresses, and Routes (Conceptual)
An IP address is always assigned to an interface (physical or virtual), not to the machine in the abstract.
On a Linux host:
- Each interface (e.g.
eth0,ens33,wlan0) can have: - One or more IPv4 addresses.
- One or more IPv6 addresses.
- The routing table decides which interface to use for traffic to a given destination network or host.
IP addressing and routing are tightly linked:
- If an IP address and netmask don’t match the router’s settings, you may not be able to reach other networks.
- Misconfigured IP addresses can cause:
- IP conflicts.
- Inability to reach gateway or internet.
- Only local-subnet access.
Routing details are covered in the “Subnets and routing” chapter; here it’s enough to know that IP addresses plus their network definitions (prefix lengths) determine which destinations are “local” vs “remote”.
Configuring IP Addresses (Conceptual Overview)
You’ll use network configuration tools and config files (covered in other chapters) to set addresses. But regardless of the tool, you’ll always be specifying:
- Address and prefix:
- IPv4:
192.168.10.5/24 - IPv6:
2001:db8:1::5/64 - Gateway (router) for that network.
- Possibly DNS servers (not part of IP addressing itself, but commonly configured together).
On Linux, IP settings may be:
- Dynamic – obtained via DHCP (v4) or SLAAC/DHCPv6 (v6).
- Static – manually specified address, prefix, gateway, etc.
Understanding the address and prefix is essential regardless of how they’re set.
Common Addressing Pitfalls
When diagnosing and planning IP schemes on Linux, watch for:
- Mismatched subnet masks/prefixes
- One host:
192.168.1.10/24 - Another:
192.168.1.20/16 - They may treat different ranges as “local”, causing routing confusion.
- IP address conflicts
- Two machines using
192.168.1.100/24on the same network. - Symptoms:
- Intermittent connectivity.
- ARP table flapping (visible with tools like
ip neigh). - Wrong gateway for the subnet
- Host IP is
10.0.1.10/24, but gateway set to10.0.0.1. - They’re in different subnets; host can’t reach the gateway as a “local” neighbor.
- Using private addresses on the public side
- WAN interface accidentally configured with
192.168.x.x, causing upstream issues. - Usually a network design problem.
- For IPv6
- Relying only on link-local
fe80::addresses where you expect global connectivity. - Missing or incorrect prefix length (e.g. using
/128where/64is needed for normal operation).
Understanding these typical failures helps you quickly narrow down IP-related issues before diving into more advanced tools.
Planning Addressing Schemes (Basic Concepts)
Even for a small lab or home network, it’s helpful to plan:
- Which private IPv4 range you’ll use:
- e.g.
192.168.10.0/24or10.0.0.0/24. - How you split subnets:
- e.g. one
/24for servers, one for desktops, one for IoT devices. - Reserving ranges:
- e.g.
.1–.50for static IPs (servers, printers). .51–.254for DHCP pool.
In formula form, for IPv4:
- Total addresses in a subnet with prefix length $p$:
$$\text{Total addresses} = 2^{32 - p}$$ - Typical usable hosts (excluding network and broadcast):
$$\text{Usable hosts} = 2^{32 - p} - 2$$
Use these formulas to estimate whether a subnet is too small or too big for your planned number of devices.
Summary
Key points you should be comfortable with before moving on:
- Recognizing IPv4 vs IPv6 formats.
- Understanding how prefix length (e.g.
/24,/64) divides network and host portions. - Identifying network, broadcast, and usable host ranges for IPv4.
- Knowing which IPv4 ranges are private vs public.
- Recognizing important special addresses like loopback and link-local.
- Seeing IP addresses as properties of interfaces, not the whole machine.
- Spotting basic addressing mistakes (wrong mask, conflicts, wrong gateway).
These concepts will be used heavily when you learn about subnets, routing, and editing Linux network configuration files in the following chapters.