17.3. Configuring Wired Interfaces

This section walks one interface, eth1, through all three backends: manual kernel state with ip (which no backend will preserve), a NetworkManager profile, a systemd-networkd file, and an ifupdown stanza. Each subsection ends with the interface in a clean state, ready for the next one.

17.3.1. Temporary Addresses and Routes with iproute2

Changes made with ip are runtime-only: nothing writes them to disk, and a reboot, a backend restart, or a profile re-activation discards or replaces them. That makes them ideal for testing an address before committing it to a profile, and for emergency fixes that must work now and be cleaned up properly later.

The configuration commands need root. Enter a root shell with sudo -i for the four ip mutations in this subsection - the block marker # identifies them - and leave it with exit once the last one is done; the verification commands in between run as john. The additions below touch only eth1 - the interface that does not carry the SSH session.

Add a second IPv4 address to the practice interface:

# ip addr add 192.168.217.50/24 dev eth1

The command produces no output when it succeeds - ip is silent unless something is wrong, so state is always confirmed separately:

$ ip -br addr show eth1
eth1             UP             192.168.217.10/24 192.168.217.50/24 2001:db8:17:1:5054:ff:fe0b:5bb6/64 fe80::5054:ff:fe0b:5bb6/64 

The interface now answers on two addresses in the same prefix. Adding an address does not create a second 192.168.217.0/24 route - the kernel already has an identical one from the original address, so the prefix keeps a single route. (noprefixroute on an address suppresses the automatic route entirely; the NetworkManager captures later in this chapter show that flag on the addresses it manages.) Next, still in the root shell, add a route through the lab gateway:

# ip route add 198.51.100.0/24 via 192.168.217.2 dev eth1 metric 200

The route command is silent too. It sends the documentation prefix 198.51.100.0/24 to router1:

$ 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 
198.51.100.0/24 via 192.168.217.2 dev eth1 metric 200 

Unlike the proto kernel entries, this route carries an explicit metric 200: it was added by an administrator, and the metric would rank it against any competing route for the same prefix. Confirm the forwarding decision, then the reachability:

$ ip route get 198.51.100.10
198.51.100.10 via 192.168.217.2 dev eth1 src 192.168.217.10 uid 1001 
    cache 
$ ping -c 2 -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.469 ms
64 bytes from 192.168.217.2: icmp_seq=2 ttl=64 time=0.409 ms

--- 192.168.217.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1006ms
rtt min/avg/max/mdev = 0.409/0.439/0.469/0.030 ms

ip route get predicted the gateway; the ping confirmed the gateway works. Neither says the remote prefix is actually reachable - router1 only forwards what it has a route for - but the host-side work is done. Back in the root shell, undo both changes in reverse order:

# ip route del 198.51.100.0/24 via 192.168.217.2 dev eth1
# ip addr del 192.168.217.50/24 dev eth1

Both are silent, and exit leaves the root shell. The state check closes the loop:

$ ip -br addr show eth1
eth1             UP             192.168.217.10/24 2001:db8:17:1:5054:ff:fe0b:5bb6/64 fe80::5054:ff:fe0b:5bb6/64 

The temporary address is gone; the original set is exactly as it was. The same add/delete vocabulary works for IPv6 with ip -6 addr and ip -6 route, and the lifetimes and privacy extensions of IPv6 addresses are covered where they matter, in Section 17.5.

17.3.2. DHCP and Static Profiles with NetworkManager

Making an address survive reboots means moving it from kernel state into a backend's configuration. eth1 currently belongs to ifupdown - an auto eth1 stanza put 192.168.217.10/24 there when the lab machines were built - so the first step of the hand-over from Section 17.2.2 is to take that stanza out. Open /etc/network/interfaces in an editor and delete the eth1 stanza, keeping everything else. The loopback and the primary interface remain:

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

That is the complete file on netlab1: lo, the untouched eth0 stanza, and nothing for eth1. Restart NetworkManager so it re-reads both the policy and the device list, in a root shell; the command prints nothing:

# systemctl restart NetworkManager

eth0 stays unmanaged - it still has a stanza, and managed=false still excludes stanzed interfaces. eth1 has no stanza and no profile, so NetworkManager adopts it in its current, externally-configured state:

$ nmcli -t -f DEVICE,STATE,CONNECTION device status
eth1:connected (externally):eth1
lo:connected (externally):lo
eth0:unmanaged:

connected (externally) is NetworkManager's honest label for a device it did not configure: the addressing put there by ifupdown still works, and the entry under CONNECTION names the assumed state rather than a saved profile. Activating any real profile replaces it.

Both profiles in this subsection need root to create, so stay in the root shell for them. The static profile gives eth1 one fixed address, the lab's DNS server, and two deliberate limits - ipv4.never-default yes keeps the primary gateway the only default route, and ipv4.route-metric 500 ranks any routes eth1 does get behind the primary interface's. ipv6.method ignore leaves IPv6 alone for now; Section 17.5 changes it:

# nmcli connection add type ethernet ifname eth1 con-name lab-static ipv4.method manual ipv4.addresses 192.168.217.20/24 ipv4.dns 192.168.217.2 ipv4.dns-search lab.example ipv4.never-default yes ipv4.route-metric 500 ipv6.method ignore
Connection 'lab-static' (015f3c66-2b5b-4287-885a-40f46e3b4609) successfully added.

nmcli connection add writes a keyfile under /etc/NetworkManager/system-connections/ - root-owned and mode 0600, which is where the profile's secrets would live too. Activate it:

# nmcli connection up lab-static
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

Activation replaces the assumed external state with the profile's configuration, and the UUID-qualified success line is the only output nmcli gives. Verify in the kernel, then in the profile:

$ ip -br addr show eth1
eth1             UP             192.168.217.20/24 2001:db8:17:1:5054:ff:fe0b:5bb6/64 fe80::5054:ff:fe0b:5bb6/64 

The static address replaced the old one, and the IPv6 addresses are untouched - ipv6.method ignore at work. The profile's own view of what it applied:

$ nmcli -t -f IP4.ADDRESS,IP4.GATEWAY,IP4.DNS connection show lab-static
IP4.ADDRESS[1]:192.168.217.20/24
IP4.GATEWAY:
IP4.DNS[1]:192.168.217.2

IP4.GATEWAY is blank because never-default declined to install the default route a manual or DHCP gateway would otherwise provide; 192.168.217.2 still serves DNS through the resolved integration covered in Section 17.6. And the gateway is reachable:

$ ping -c 2 -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.774 ms
64 bytes from 192.168.217.2: icmp_seq=2 ttl=64 time=0.404 ms

--- 192.168.217.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1026ms
rtt min/avg/max/mdev = 0.404/0.589/0.774/0.185 ms

The DHCP profile differs in one property - ipv4.method auto - and demonstrates that a profile can be replaced on the same interface without deleting anything:

# nmcli connection add type ethernet ifname eth1 con-name lab-dhcp ipv4.method auto ipv4.route-metric 500 ipv4.never-default yes ipv6.method ignore
Connection 'lab-dhcp' (1aeab7fc-fe1c-496d-abc5-2f50cf1a664a) successfully added.
# nmcli connection up lab-dhcp
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)

router1's DHCP server - the dnsmasq pool on the practice LAN - assigned an address from its range:

$ ip -br addr show eth1
eth1             UP             192.168.217.150/24 2001:db8:17:1:5054:ff:fe0b:5bb6/64 fe80::5054:ff:fe0b:5bb6/64 
$ nmcli -t -f IP4.ADDRESS,IP4.GATEWAY,IP4.DNS connection show lab-dhcp
IP4.ADDRESS[1]:192.168.217.150/24
IP4.GATEWAY:
IP4.DNS[1]:192.168.217.2

The lease carried 192.168.217.2 as both router and DNS option; never-default again kept the router option from becoming a second default route, and the DNS server was registered with systemd-resolved (Section 17.6.3 shows that registration from the other side). Reachable as before:

$ ping -c 2 -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.418 ms
64 bytes from 192.168.217.2: icmp_seq=2 ttl=64 time=0.368 ms

--- 192.168.217.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1023ms
rtt min/avg/max/mdev = 0.368/0.393/0.418/0.025 ms

Finally, the profile list shows the machine's complete state, including entries NetworkManager generated on its own:

$ nmcli -t -f NAME,TYPE,DEVICE connection show
lab-dhcp:802-3-ethernet:eth1
lo:loopback:lo
Ifupdown (eth0):802-3-ethernet:
Wired connection 1:802-3-ethernet:
lab-static:802-3-ethernet:

lab-dhcp is active on eth1; lab-static is saved but inactive, and nmcli connection up lab-static would swap back to it. lo is NetworkManager's generated loopback profile. Ifupdown (eth0) is the read-only placeholder the ifupdown plugin creates so the GUI can display the unmanaged interface, and Wired connection 1 is the default profile NetworkManager generates for an Ethernet device it manages with no other profile - here never activated because lab-dhcp claimed the device first. Both generated entries are harmless, and both disappear with nmcli connection delete if they are never wanted.

On a desktop, the same profiles exist behind the settings panel: the Wi-Fi and network pages of GNOME or KDE Plasma write the keyfiles nmcli reads, and nm-connection-editor exposes the full property set graphically. A profile created by root with nmcli is a system connection, usable before any user logs in; profiles created from a desktop session belong to that user unless moved to /etc/NetworkManager/system-connections/ with correct ownership.

17.3.3. Persistent Server Configuration with systemd-networkd

The systemd-networkd hand-over demonstrates the server pattern: plain files, no interactive client, userspace DHCP and RA. The procedure follows Section 17.2.2 exactly, and it starts by stopping the old owner on this link. Stay in a root shell throughout this subsection.

Warning: The next commands stop NetworkManager on netlab1. The SSH session runs over eth0, which ifupdown configured and which is not being touched; stopping the daemon does not disturb it. The exercises deliberately keep the session's link under a different owner.

# systemctl stop NetworkManager

The stop is silent. The kernel state eth1 carries is still the DHCP lease from the last profile, because stopping a backend never un-does its work - flush it so the new backend starts clean:

# ip addr flush dev eth1 && ip -6 addr flush dev eth1 scope global

The two stages are one cleanup: ip addr flush dev eth1 removes all IPv4 addresses from the link, and ip -6 addr flush ... scope global removes the global IPv6 addresses while leaving the link-local address, which belongs to the link rather than to any backend. Both are silent.

Now the configuration. systemd-networkd files match links, then configure them:

# /etc/systemd/network/20-eth1-lab.network
[Match]
Name=eth1

[Network]
Address=192.168.217.30/24
DNS=192.168.217.2
Domains=lab.example
IPv6AcceptRA=no
LinkLocalAddressing=ipv6

Every line of that file does one job. [Match] Name=eth1 selects the device - the same file could instead match Name=eth1 eth2 or a MAC address, or the alternative names from Section 17.1.3. Address= is the static IPv4 address. DNS= and Domains= register the lab resolver and the lab.example search domain with systemd-resolved for this link (Section 17.6.3). IPv6AcceptRA=no keeps this exercise deliberately IPv4-only; the setting is enabled by default, and Section 17.5.1 works through the RA processing it controls. LinkLocalAddressing=ipv6 keeps the link-local address. One deliberate omission: there is no Gateway=, because eth0 owns the default route here. A server whose only network was eth1 would add Gateway= 192.168.217.2 - or a [Route] section with Gateway= and Metric= when more control is needed, per systemd.network(5).

Enable the daemon - it ships with systemd, so there is nothing to install:

# systemctl enable --now systemd-networkd
Created symlink '/etc/systemd/system/dbus-org.freedesktop.network1.service' → '/usr/lib/systemd/system/systemd-networkd.service'.
Created symlink '/etc/systemd/system/multi-user.target.wants/systemd-networkd.service' → '/usr/lib/systemd/system/systemd-networkd.service'.
Created symlink '/etc/systemd/system/sockets.target.wants/systemd-networkd.socket' → '/usr/lib/systemd/system/systemd-networkd.socket'.
Created symlink '/etc/systemd/system/sysinit.target.wants/systemd-network-generator.service' → '/usr/lib/systemd/system/systemd-network-generator.service'.
Created symlink '/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service' → '/usr/lib/systemd/system/systemd-networkd-wait-online.service'.

Enabling the service also enables the units around it: systemd-networkd.socket lets D-Bus requests start the daemon on demand, systemd-network-generator translates kernel command-line network arguments into .network files at boot, and systemd-networkd-wait-online.service holds back network-online.target until configured links are up - the target other services use to declare they need a network. Make networkd read the new file and apply it:

# networkctl reload && networkctl reconfigure eth1

reload re-reads the configuration files; reconfigure re-applies configuration to a link that is already up. Both are silent - but networkd's own status command is the rich one:

$ networkctl status eth1 --no-pager
● 3: eth1
                   Link File: /usr/lib/systemd/network/99-default.link
                Network File: /etc/systemd/network/20-eth1-lab.network
                       State: routable (configuring)
                Online state: online
                        Type: ether
                        Path: pci-0000:00:06.0
                      Driver: virtio_net
                      Vendor: Red Hat, Inc.
                       Model: Virtio network device
           Alternative Names: enp0s6
                              ens6
                              enx5254000b5bb6
            Hardware Address: 52:54:00:0b:5b:b6
                         MTU: 1500 (min: 68, max: 65535)
                       QDisc: fq_codel
IPv6 Address Generation Mode: eui64
    Number of Queues (Tx/Rx): 1/1
            Auto negotiation: no
                     Address: 192.168.217.30
                         DNS: 192.168.217.2
              Search Domains: lab.example
           Activation Policy: up
         Required For Online: yes

This is the same evidence Section 17.1.3 promised: the PCI path, driver, vendor, and all three alternative names in one place, plus the two lines that prove the file took effect - Network File: names the matching configuration, and the Address:, DNS:, and Search Domains: lines carry its values. State: routable (configuring) means the link has addresses and can forward traffic, with per-link setup still completing at that moment; Online state: online is networkd's verdict that the link met its Required For Online condition. The kernel agrees:

$ ip -br addr show eth1
eth1             UP             192.168.217.30/24 
$ 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.30 

The route table is the hand-over's receipt: the prefix route now has networkd's source address, and the default route never moved off eth0. Reachability closes the exercise:

$ ping -c 2 -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.721 ms
64 bytes from 192.168.217.2: icmp_seq=2 ttl=64 time=0.382 ms

--- 192.168.217.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1011ms
rtt min/avg/max/mdev = 0.382/0.551/0.721/0.169 ms
networkctl command Description
status [LINK] Show one link or the overall state; names the link and network files that matched.
list One line per link with state and type.
reload Re-read configuration files after editing them.
reconfigure LINK Re-apply configuration to a running link.
-a / --all Include links that are down or unconfigured in listings.
--no-pager Send long output directly to the terminal instead of a pager.

Undo the exercise in the hand-over order - stop the backend, remove its file, flush the link:

# systemctl stop systemd-networkd
Stopping 'systemd-networkd.service', but its triggering units are still active:
systemd-networkd.socket

The message is not an error: systemd-networkd.socket stays listening so that a D-Bus request can start the daemon again, which is what socket activation means for this service.

# rm -f /etc/systemd/network/20-eth1-lab.network
# ip addr flush dev eth1 && ip -6 addr flush dev eth1 scope global

Both silent, as before. eth1 now belongs to nobody - the exact state Section 17.2.2 called valid.

17.3.4. Maintaining Existing ifupdown Configuration

ifupdown configuration lives in stanzas. The one used here goes in its own file under the directory the main file already sources:

# /etc/network/interfaces.d/eth1-lab
auto eth1
iface eth1 inet static
    address 192.168.217.40/24
    dns-nameservers 192.168.217.2
    dns-search lab.example

auto eth1 makes ifup -a raise the interface at boot. The iface line declares the address family and method; static here, dhcp for a leased address. address accepts CIDR notation in ifupdown 0.8.44, so one line replaces the older address/netmask pair - ifquery below shows both expanded forms anyway. The dns-* options are recorded for resolver integrations (openresolv and friends) to consume; on this machine /etc/resolv.conf belongs to systemd-resolved, so they change nothing by themselves, and DNS ownership stays where Section 17.6.3 puts it.

With the stanza saved, take the interface down. Nothing is configured on it after the previous subsection's flush, so this first ifdown reports the mismatch rather than removing anything - and that observation is instructive enough to keep:

# ifdown eth1
Error: ipv4: Address not found.

ifdown deconfigures by reading the current stanza - the new 192.168.217.40 - and that address is not on the interface, because the previous backend removed everything. The message means "nothing to remove", not "the stanza is broken". Apply the stanza:

# ifup eth1

ifup is silent on success. Confirm what the running configuration now is, first through ifupdown's own query:

# ifquery eth1
address: 192.168.217.40
dns-nameservers: 192.168.217.2
dns-search: lab.example
broadcast: 192.168.217.255
netmask: 255.255.255.0

ifquery prints the effective stanza: the author's input plus the broadcast and netmask ifupdown derived from the /24. Then through the kernel, as john:

$ ip -br addr show eth1
eth1             UP             192.168.217.40/24 fe80::5054:ff:fe0b:5bb6/64 

The link-local address is present because the link is up - ifupdown does not manage it either. Reachability:

$ ping -c 2 -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.670 ms
64 bytes from 192.168.217.2: icmp_seq=2 ttl=64 time=0.426 ms

--- 192.168.217.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1031ms
rtt min/avg/max/mdev = 0.426/0.548/0.670/0.122 ms
ifupdown command Description
ifup IFACE Apply the stanza for IFACE: bring the link up and configure it.
ifdown IFACE Reverse ifup: deconfigure and bring the link down.
ifquery IFACE Print the effective stanza, with derived values such as netmask.
ifquery --list List the interfaces ifup -a would raise (auto stanzas).
ifup -a Raise every auto interface; the boot sequence's action.

Take it down again - this time there is something to remove, so the command is silent:

# ifdown eth1
$ ip -br addr show eth1
eth1             DOWN           

DOWN with no addresses is ifupdown's clean deconfigured state: the kernel link is administratively down, not merely empty. Remove the stanza file so a reboot cannot resurrect the configuration, and bring NetworkManager back for the wireless section that follows:

# rm -f /etc/network/interfaces.d/eth1-lab
# systemctl start NetworkManager

Both commands are silent. On restart NetworkManager finds its saved profiles and auto-activates the one that matches eth1 - visible in the next section's captures, where eth1 reports connected to lab-dhcp again. One file, one owner, one deletion: the whole cycle.