17.1. Understanding the Host Network

The kernel exposes links, addresses, routes, and neighbor entries through the iproute2 tools, and everything the configuration backends do is ultimately written into that kernel state. Reading it directly is the skill that survives backend changes, and every diagnosis later in the chapter starts from it.

ip shows three layers. A link is the network device - eth1, a wireless interface, a bridge, the loopback. An address belongs to a link. A route says which link, and possibly which gateway, carries packets for a destination prefix. Start with the brief form of the link list, on netlab1 as john:

$ ip -br link show
lo               UNKNOWN        00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP> 
eth0             UP             52:54:00:f4:e6:21 <BROADCAST,MULTICAST,UP,LOWER_UP> 
eth1             UP             52:54:00:0b:5b:b6 <BROADCAST,MULTICAST,UP,LOWER_UP> 

-br asks for one brief line per device: name, operating state, media address, and flag set. lo is always UNKNOWN because it has no carrier to detect; the two Ethernet devices are UP with LOWER_UP, meaning the administrative state and the physical link are both active. A cable pulled from a running interface would show NO-CARRIER here.

ip option Description
-br Brief output: one line per object with the important fields only.
-d Detailed output, including driver, queueing discipline, and alternative names.
-o One-line output, one record per line; useful in scripts with read.
-c Colorize state and address families when the terminal supports it.
-4 / -6 Restrict the command to IPv4 or IPv6 objects.

The detailed form of one link adds what the flags abbreviate:

$ ip -d link show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:0b:5b:b6 brd ff:ff:ff:ff:ff:ff promiscuity 0 allmulti 0 minmtu 68 maxmtu 65535 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 gso_ipv4_max_size 65536 gro_ipv4_max_size 65536 parentbus virtio parentdev virtio3 
    altname enp0s6
    altname ens6
    altname enx5254000b5bb6

The interface number, MTU, queueing discipline, and driver parent bus come from the kernel; the altname lines are the alternative names udev could have assigned (Section 17.1.3 explains them). addrgenmode eui64 says how the kernel derives an IPv6 link-local address from the media address - a detail that matters in Section 17.5. Now the addresses:

$ ip -br addr show
lo               UNKNOWN        127.0.0.1/8 ::1/128 
eth0             UP             192.168.121.24/24 fe80::5054:ff:fef4:e621/64 
eth1             UP             192.168.217.10/24 2001:db8:17:1:5054:ff:fe0b:5bb6/64 fe80::5054:ff:fe0b:5bb6/64 

eth1 carries three addresses in two families. 192.168.217.10/24 is a global IPv4 address; the /24 is the prefix length, the number of leading bits that identify the network, leaving 8 bits for hosts. 2001:db8:17:1:5054:ff:fe0b:5bb6/64 is a global IPv6 address, and fe80::5054:ff:fe0b:5bb6/64 is IPv6 link-local - every interface always has one, and Section 17.5.2 treats it as a distinct scope rather than a second "normal" address. Routes make the prefixes usable:

$ ip route show
default via 192.168.121.1 dev eth0 
192.168.121.0/24 dev eth0 proto kernel scope link src 192.168.121.24 
192.168.217.0/24 dev eth1 proto kernel scope link src 192.168.217.10 

Three entries answer every IPv4 forwarding decision. The two proto kernel scope link routes were created automatically when the addresses were assigned: destinations inside 192.168.217.0/24 are neighbors on eth1, reached directly, with 192.168.217.10 as source. Everything else matches the default route, which points at the primary network's gateway. Reading the table in most-specific-first order - /24 before /0 - is exactly what the kernel does.

Two facts about this output organize the rest of the chapter. First, ip shows runtime state: everything above was true at this moment, regardless of which program put it there, and a reboot or a backend restart can change it. Second, the state is consistent because one program per interface produced it. Section 17.2 shows how to check that, and Section 17.3 changes it deliberately.

17.1.2. IPv4, IPv6, Neighbor Discovery, and Default Gateways

IPv4 and IPv6 differ most visibly in how a host learns its neighbors. IPv4 wraps address resolution in ARP, a separate protocol that asks the whole segment "who has 192.168.217.2?". IPv6 folds the same function into Neighbor Discovery (ND), part of ICMPv6, and adds router discovery in the same mechanism: a router announces itself, the prefix, and DNS information in periodic Router Advertisements (RAs), and the host configures itself from them. The netlab1 captures show both families working side by side:

$ ip -6 addr show dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    altname enp0s6
    altname ens6
    altname enx5254000b5bb6
    inet6 2001:db8:17:1:5054:ff:fe0b:5bb6/64 scope global dynamic mngtmpaddr proto kernel_ra 
       valid_lft 86392sec preferred_lft 14392sec
    inet6 fe80::5054:ff:fe0b:5bb6/64 scope link proto kernel_ll 
       valid_lft forever preferred_lft forever

The global address was not configured by hand. Its flags say so: proto kernel_ra means the kernel's RA processing created it from the prefix 2001:db8:17:1::/64 that router1 advertises, dynamic and the lifetimes mean it expires unless the router keeps confirming it, and the interface identifier 5054:ff:fe0b:5bb6 is derived from the MAC address 52:54:00:0b:5b:b6 by the EUI-64 rule - insert ff:fe in the middle and flip one bit. The link-local address below it is marked proto kernel_ll: the kernel generates it at link-up, no router required.

The IPv6 routing table shows the other half of what the advertisement provided:

$ ip -6 route show
2001:db8:17:1::/64 dev eth1 proto kernel metric 256 expires 86399sec pref medium
fe80::/64 dev eth0 proto kernel metric 256 pref medium
fe80::/64 dev eth1 proto kernel metric 256 pref medium
default via fe80::5054:ff:fee7:63fb dev eth1 proto ra metric 1024 expires 29sec hoplimit 64 pref medium

The default route is worth reading closely. Its gateway is a link-local address - IPv6 gateways are always addressed by link-local identifiers, so a renumbered site can change every global prefix without the host needing a new gateway address. It is marked proto ra, and it expires with the router lifetime, refreshed by each arriving advertisement. A router that stops advertising is forgotten on schedule rather than black-holing traffic forever. There is no DHCPv6, no per-host file, and no manual route: SLAAC - Stateless Address Autoconfiguration - produced both the address and the route. Section 17.5.1 unpacks the flags that switch between SLAAC, DHCPv6, and static configuration.

Before treating any of this as healthy, prove the path works one layer at a time. First the gateway, with the two options used throughout the chapter:

$ ping -c 3 -W 1 192.168.217.2
PING 192.168.217.2 (192.168.217.2) 56(84) bytes of data.
64 bytes from 192.168.217.2: icmp_seq=1 ttl=64 time=0.747 ms
64 bytes from 192.168.217.2: icmp_seq=2 ttl=64 time=0.392 ms
64 bytes from 192.168.217.2: icmp_seq=3 ttl=64 time=0.306 ms

--- 192.168.217.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2039ms
rtt min/avg/max/mdev = 0.306/0.481/0.747/0.190 ms
ping option Description
-c COUNT Stop after COUNT packets instead of running until interrupted.
-W SECONDS Give up on a reply after SECONDS; without a bound, one lost packet can stall a script for a long time.
-I IFACE\|ADDRESS Send on a specific interface or from a specific source address.
-M do\|dont Set or clear the Don't-Fragment bit; -M do with -s probes path MTU (Section 17.7.4).
-s SIZE Send SIZE bytes of ICMP payload (default 56).
-6 Force IPv6 even for a literal address.

The reply proves three layers at once: the link carries frames, the addressing is right, and the gateway answers. Now the neighbor table that made it possible:

$ ip neigh show
192.168.217.2 dev eth1 lladdr 52:54:00:e7:63:fb REACHABLE 
192.168.121.1 dev eth0 lladdr 52:54:00:cb:2a:0c REACHABLE 
fe80::5054:ff:fee7:63fb dev eth1 lladdr 52:54:00:e7:63:fb router STALE 

The two IPv4 rows are the ARP results: the kernel knows which MAC owns each gateway and marks both REACHABLE, confirmed by recent traffic. The IPv6 row is the ND equivalent, with one extra word: router flags a neighbor that issued a router advertisement. STALE means the entry has not been confirmed lately; the next packet triggers reconfirmation instead of failing. Other common states are DELAY and PROBE during that reconfirmation, INCOMPLETE while a query is outstanding, and FAILED when nobody answered - a failed gateway entry is the standard signature of a link-layer problem below a correct-looking IP configuration.

For a single destination, ip route get shows the decision the kernel would make without walking the whole table:

$ ip route get 192.168.217.2
192.168.217.2 dev eth1 src 192.168.217.10 uid 1001 
    cache 

The output names the outgoing device, the source address chosen for new connections, and - under the uid field - the user on whose behalf the lookup ran. It answers the two questions that dominate misconfiguration reports: "which link did that actually use?" and "which source address will the peer see?". The same query with an IPv6 address works in the -6 table and appears in Section 17.5.4.

One sysctl controls whether the kernel itself processes router advertisements:

$ cat /proc/sys/net/ipv6/conf/eth1/accept_ra
1

1 accepts RAs on a non-forwarding host, which netlab1 is. The kernel refuses RAs when IPv6 forwarding is on unless this is raised to 2, a distinction that matters on routers. There is a second, easily missed detail: systemd-networkd runs its own userspace RA client and forces the kernel's out of the way when it owns a link, so a machine can show 0 here while still learning IPv6 correctly through networkd (Section 17.5.1). Persistent sysctl settings, including this one, are covered in Chapter 7.

17.1.3. Predictable Interface Names and Device Identification

Interface names are assigned by udev from systemd's link-naming rules: names encode where the device sits - en for Ethernet, wl for wireless, ww for cellular - followed by a slot or path identifier, as in enp0s6 for the PCI device at bus 0, slot 6. The point is stability: two identical add-in cards keep distinct, reproducible names across reboots, and a replaced card does not silently inherit the old one's name. Debian installs made with the installer use these names by default.

The lab machines are an exception worth understanding rather than copying: they boot with net.ifnames=0, a kernel parameter that disables renaming, so their interfaces keep the kernel's initial eth0/eth1 names. Even then the predictable candidates are not lost - the altname lines in Section 17.1.1's output expose enp0s6, ens6, and enx5254000b5bb6, and any of the three can be used as an alternative spelling for the same device:

altname enp0s6
altname ens6
altname enx5254000b5bb6

The three families are worth recognizing on any machine: enp0s6 encodes the PCI path, ens6 a hotplug slot ID, and enx5254000b5bb6 the permanent MAC address. Wireless names follow the same scheme with a wl prefix - the wlan0 created in Section 17.4 would be named by slot on a renamed system. When a name and its altname disagree with the physical port you plugged, the device path settles it: networkctl status eth1 prints Path: pci-0000:00:06.0 with the driver, vendor, and model (the capture appears in Section 17.3.3), and udevadm info /sys/class/net/eth1 reports the same evidence from udev's side, including ID_NET_NAME_PATH and the naming scheme in use. Naming rules can also be pinned explicitly with a systemd .link file; that mechanism, and udev rules generally, are covered in Chapter 7.

Names are only identification. Configuration always belongs to a backend, and the next section decides which one.