LFCS 96 ๐ง Network Interfaces โ ip addr
The ip command from the iproute2 suite has replaced the legacy ifconfig and route tools on virtually every modern Linux distribution. For the LFCS exam, ip addr is the essential tool for inspecting and modifying network interface addresses. The command operates on live kernel state, which means every change made with ip addr add or ip addr del is volatile and will not survive a reboot unless persisted through a network manager like NetworkManager or Netplan. Understanding this distinction between runtime configuration and persistent configuration is the difference between a working interface and a broken boot sequence.
Key point: ip addr manages protocol addresses on interfaces. It does not bring interfaces up or downโthat is the domain of ip link. An interface with an IP address but in a DOWN state cannot pass traffic.
Why ip addr exists
The ifconfig problem. The net-tools package, containing ifconfig, route, and arp, has not seen active development in decades. It cannot handle modern networking features like multiple addresses per interface with proper labeling, IPv6 privacy extensions, or network namespaces. The iproute2 suite was designed as a unified replacement, and ip addr is its address management component .
The multi-address problem. A single interface can have multiple IP addresses, and ifconfig handles this poorly through “aliases” like eth0:0. The ip addr command treats every address as a first-class citizen attached to the interface, with labels for backward compatibility and proper scoping for IPv6 .
The runtime persistence problem. Every change made with ip addr add modifies the running kernel state immediately. This is powerful for testing and troubleshooting, but dangerous if mistaken for a persistent configuration. A reboot wipes the change. The LFCS exam tests both the immediate command and the knowledge that persistence requires NetworkManager (nmcli), Netplan, or distribution-specific configuration files .
The IPv6 problem. IPv6 introduces concepts that ifconfig was never designed to handle: duplicate address detection (DAD), valid and preferred lifetimes, temporary privacy addresses, and scoped addresses (link, host, global). The ip addr command exposes these directly through flags like nodad, mngtmpaddr, and valid_lft .
The trade-off. ip addr has a steeper learning curve than ifconfig. The syntax is more structured (ip [object] [command]), and the output includes details that beginners may not need. The benefit is precision: every aspect of the address configuration is explicitly controllable.
a. Displaying interface addresses
The show subcommand (or no subcommand at all) lists the addresses attached to every interface. The output includes the interface name, its state, the MAC address, and every IPv4 and IPv6 address with its prefix length and scope.
# Show all addresses on all interfaces
ip addr show
# Shorthand
ip addr
# Show only IPv4 addresses
ip -4 addr show
# Show only IPv6 addresses
ip -6 addr show
# Show a specific interface
ip addr show dev enp0s3
The output for an interface in the UP state includes the inet line for IPv4 and inet6 lines for IPv6. An interface without an address shows only the link/ether line and is marked DOWN . The -c flag colorizes the output, which helps visually distinguish active from inactive interfaces .
The scope field is critical for IPv6. A link scope address is valid only on the local segment (e.g., fe80::/64). A global scope address is routable. A host scope address is valid only within the machine itself .
b. Adding and removing addresses
The add subcommand attaches a new address to an interface. The address must include the prefix length (/24 for IPv4, /64 for IPv6). Without it, the kernel may derive a default that is not what you intended.
# Add an IPv4 address
sudo ip addr add 192.168.1.100/24 dev enp0s3
# Add an IPv6 address
sudo ip addr add 2001:db8::1/64 dev enp0s3
# Add a secondary address with a label
sudo ip addr add 192.168.1.101/24 dev enp0s3 label enp0s3:1
The label option preserves compatibility with the old eth0:0 alias syntax. The label must begin with the interface name followed by a colon, and the total length cannot exceed 15 characters . This label is purely cosmetic for tools that still look for alias-style interfaces; the kernel treats the address as attached to the base interface.
Removing an address requires the exact address and prefix length that was added. If the prefix differs, the kernel will not find the address to delete.
# Remove an address
sudo ip addr del 192.168.1.100/24 dev enp0s3
# Flush all addresses from an interface
sudo ip addr flush dev enp0s3
The flush command removes every address from the interface without deleting the interface itself. This is useful when reconfiguring an interface but is dangerous if applied to the wrong device .
c. Advanced options and persistence
The ip addr command accepts options that modify the behavior of the address after it is added. These options are critical for IPv6 and for interfaces with specific routing requirements.
| Option | Effect |
|---|---|
nodad | Skip Duplicate Address Detection (IPv6 only) |
mngtmpaddr | Manage temporary privacy addresses from this template (IPv6) |
noprefixroute | Do not automatically add a route for the prefix |
valid_lft | Lifetime until the address is removed |
preferred_lft | Lifetime until the address is no longer used for new connections |
The valid_lft and preferred_lft options are particularly relevant for IPv6, where addresses have finite lifetimes defined by the router advertisement. Setting them manually overrides the kernel’s defaults .
Every change made with ip addr is runtime-only. To persist the configuration across reboots, the address must be configured through the system’s network manager. On systems using NetworkManager, nmcli is the tool. On Ubuntu systems using Netplan, the configuration is written to a YAML file under /etc/netplan/ and applied with netplan apply .
# NetworkManager: add a static address persistently
sudo nmcli connection modify "Wired connection 1" \
+ipv4.addresses 192.168.1.100/24
# Netplan: edit the YAML file, then apply
sudo nano /etc/netplan/01-netcfg.yaml
sudo netplan apply
Complete Example Session
# ============================================
# PART 1: LIST ALL INTERFACES
# ============================================
ip addr show
# Output shows lo, enp0s3, and enp0s8.
# enp0s3 has an address; enp0s8 is DOWN.
# ============================================
# PART 2: INSPECT A SPECIFIC INTERFACE
# ============================================
ip addr show dev enp0s3
# Output includes inet 10.0.2.15/24 and link/ether.
# ============================================
# PART 3: ADD AN ADDRESS AT RUNTIME
# ============================================
sudo ip addr add 192.168.1.50/24 dev enp0s8
# The address is attached immediately.
# The interface is still DOWN until ip link set up.
# ============================================
# PART 4: BRING THE INTERFACE UP
# ============================================
sudo ip link set enp0s8 up
# The interface transitions to UP.
# ============================================
# PART 5: VERIFY THE NEW ADDRESS
# ============================================
ip addr show dev enp0s8
# Output shows inet 192.168.1.50/24 brd 192.168.1.255.
# ============================================
# PART 6: ADD A SECONDARY ADDRESS WITH LABEL
# ============================================
sudo ip addr add 192.168.1.51/24 dev enp0s8 label enp0s8:1
# The label preserves alias compatibility.
# ============================================
# PART 7: REMOVE AN ADDRESS
# ============================================
sudo ip addr del 192.168.1.50/24 dev enp0s8
# The address is removed from the interface.
# ============================================
# PART 8: FLUSH ALL ADDRESSES
# ============================================
sudo ip addr flush dev enp0s8
# All addresses are removed, but the interface remains UP.
# ============================================
# PART 9: PERSIST THE CONFIGURATION
# ============================================
# On NetworkManager systems:
sudo nmcli connection modify "Wired connection 1" \
+ipv4.addresses 192.168.1.50/24
sudo nmcli connection up "Wired connection 1"
The nine parts trace the lifecycle: listing, inspecting, adding, bringing up, verifying, labeling, removing, flushing, and persisting. The critical distinction is between the runtime command and the persistent configuration.
Quick Reference
ip addr Commands
| Command | Purpose |
|---|---|
ip addr show | List all addresses |
ip addr show dev eth0 | Show one interface |
ip -4 addr show | IPv4 only |
ip -6 addr show | IPv6 only |
ip addr add 192.168.1.1/24 dev eth0 | Add an address |
ip addr del 192.168.1.1/24 dev eth0 | Remove an address |
ip addr flush dev eth0 | Remove all addresses |
Address Options
| Option | Scope |
|---|---|
label eth0:0 | Alias compatibility |
scope global | Routable address |
scope link | Link-local only |
nodad | Skip DAD (IPv6) |
noprefixroute | No automatic prefix route |
valid_lft 3600 | Lifetime in seconds |
Persistence Tools
| Tool | System |
|---|---|
nmcli | NetworkManager (RHEL, Fedora, modern Ubuntu) |
netplan | Ubuntu (YAML under /etc/netplan/) |
ifcfg files | Older RHEL/CentOS (/etc/sysconfig/network-scripts/) |
Best Practices
โ Do This:
ip addr add 192.168.1.50/24 dev enp0s8
<!-- Always include the prefix length --> # โ
ip addr show dev enp0s8
<!-- Verify the address after adding --> # โ
sudo nmcli connection modify ... +ipv4.addresses ...
<!-- Persist the configuration --> # โ
โ Don’t Do This:
ip addr add 192.168.1.50 dev enp0s8
<!-- Missing prefix length --> # โ
ip addr flush dev enp0s3
<!-- Flushing the primary interface kills connectivity --> # โ
# Assume ip addr add persists across reboot
<!-- Runtime changes are volatile --> # โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Address lost after reboot | Runtime-only change | Configure with nmcli or Netplan |
| Interface DOWN despite address | ip addr does not bring link up | ip link set dev up |
| Delete fails | Prefix length mismatch | Use the exact /prefix from ip addr show |
| Cannot reach gateway | Missing route | Add route with ip route add |
ifconfig not found | net-tools not installed | Use ip addr or install net-tools |
Real-World Examples
1. Show All Addresses
ip addr show
2. Show IPv4 Only
ip -4 addr show
3. Add Address
sudo ip addr add 10.0.0.5/24 dev eth0
4. Add with Label
sudo ip addr add 10.0.0.6/24 dev eth0 label eth0:1
5. Remove Address
sudo ip addr del 10.0.0.5/24 dev eth0
6. Flush Interface
sudo ip addr flush dev eth0
7. Persist with nmcli
sudo nmcli con mod "eth0" +ipv4.addresses 10.0.0.5/24
8. Persist with Netplan
sudo netplan apply
9. Colorized Output
ip -c addr show
10. Check for Duplicate IPs
ip addr show | grep inet
Visual
ip addr vs ip link
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ip link set enp0s8 up โ
โ (Layer 2: administratively enables link) โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ip addr add 192.168.1.50/24 dev enp0s8 โ
โ (Layer 3: assigns protocol address) โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Interface is UP with an address โ
โ Traffic can flow โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
An address on a DOWN interface does nothing. The link must be enabled first.
Runtime vs Persistent
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ip addr add 192.168.1.50/24 dev eth0 โ
โ Immediate effect. Lost on reboot. โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ nmcli connection modify ... โ
โ Stored in /etc/NetworkManager/ โ
โ Applied at boot. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The two commands achieve the same runtime state, but only one survives a reboot.
Summary
| Item | Value |
|---|---|
| Address display | ip addr show |
| Address add | ip addr add /dev |
| Address remove | ip addr del /dev |
| Address flush | ip addr flush dev |
| IPv4 only | ip -4 addr |
| IPv6 only | ip -6 addr |
| Label syntax | label eth0:1 |
| Persistence | nmcli or Netplan |
| Runtime only | Yes (lost on reboot) |
Key takeaways:
ip addrmanages Layer 3 addresses. It does not bring interfaces up or downโthat isip link.- Every change is runtime-only. Persistence requires NetworkManager (
nmcli), Netplan, or distribution-specific files . - The prefix length is mandatory. Without it, the kernel may derive an unintended netmask.
- Multiple addresses per interface are normal. Labels provide alias compatibility, but the kernel treats each address independently .
- IPv6 addresses have lifetimes.
valid_lftandpreferred_lftcontrol when the address expires and when it stops being used for new connections .
Remember: ip addr is the inspection and modification tool for protocol addresses. It is not the tool for bringing links up, adding routes, or persisting configuration. The LFCS exam tests the distinction: the command for the immediate change, and the command for the permanent change.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!