109.2 Persistent Network Configuration

Weight: 4

Goal: Configure network settings on a Linux host so they survive reboots, and manage them at runtime.

This objective is about how Linux stores and applies the network configuration you saw in 109.1.


1. The Many Ways Linux Configures the Network

A single Linux machine may use any one of several network-management systems. The exam expects you to recognize the configuration files and tools used by each:

System Used by Configuration
Classic Debian-style ifupdown Debian (legacy) /etc/network/interfaces
Classic Red Hat-style network scripts RHEL/CentOS 7 and earlier /etc/sysconfig/network-scripts/ifcfg-*
NetworkManager Most modern desktops nmcli, nmtui
systemd-networkd Modern servers, embedded /etc/systemd/network/*.network
Netplan Ubuntu 18.04+ /etc/netplan/*.yaml (renders to one of the above)

You don’t have to master every one. Recognize them and know the file or command that goes with each.


2. The Debian-Style File: /etc/network/interfaces

Read by the ifup / ifdown commands. Each block configures one interface.

# loopback
auto lo
iface lo inet loopback

# Ethernet — DHCP
auto eth0
iface eth0 inet dhcp

# Ethernet — static
auto eth1
iface eth1 inet static
    address 192.168.1.10
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 192.168.1.1 8.8.8.8

Important keywords:

Keyword Meaning
auto IFACE Bring the interface up automatically at boot.
iface IFACE inet METHOD Define an IPv4 (inet) configuration. Use inet6 for IPv6.
Methods loopback, dhcp, static, manual
address, netmask, gateway Static IPv4 settings.
dns-nameservers DNS servers (requires resolvconf package).
pre-up, up, down, post-down Commands to run at each phase.

To apply changes: ifup eth0, ifdown eth0, or systemctl restart networking.


3. The Red Hat-Style Files: ifcfg-*

In RHEL/CentOS 7 and earlier, each interface has its own file /etc/sysconfig/network-scripts/ifcfg-<name>.

# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=1.1.1.1

Important variables:

Variable Meaning
DEVICE Interface name.
ONBOOT=yes/no Bring up at boot.
BOOTPROTO static, dhcp, or none.
IPADDR, NETMASK, GATEWAY Static IPv4.
DNS1, DNS2 DNS servers.

A few global settings live in /etc/sysconfig/network (hostname, default gateway).

Apply with systemctl restart network (older RHEL) or nmcli connection reload (when NetworkManager owns the file, which is the case on modern Red Hat systems).


4. NetworkManager and nmcli

NetworkManager is the default network service on most modern Linux desktops and on recent RHEL/CentOS releases. It auto-detects connections, handles Wi-Fi, VPN, and Ethernet, and persists “connection profiles” on disk.

nmcli — the command-line tool

nmcli                                  # overall status
nmcli device status                    # list interfaces and their state
nmcli connection show                  # list known connection profiles
nmcli connection show eth0             # details for one profile

# Bring a connection up/down
nmcli connection up eth0
nmcli connection down eth0

# Create a static profile
nmcli connection add type ethernet \
    con-name "home" ifname eth0 \
    ipv4.method manual \
    ipv4.addresses 192.168.1.10/24 \
    ipv4.gateway 192.168.1.1 \
    ipv4.dns "8.8.8.8 1.1.1.1"

# Modify an existing one
nmcli connection modify "home" ipv4.addresses 192.168.1.20/24
nmcli connection reload

There is also nmtui — a curses-based menu version of nmcli.

NetworkManager stores its profiles under /etc/NetworkManager/system-connections/ (per-connection .nmconnection files), but you should normally edit them through nmcli.


5. systemd-networkd (Awareness)

A lightweight network manager for servers and embedded systems. Configuration goes in /etc/systemd/network/:

# /etc/systemd/network/20-wired.network
[Match]
Name=eth0

[Network]
DHCP=yes

Managed with systemctl start/enable systemd-networkd. You only need to recognize this system for the exam.


6. Hostname

The system’s hostname is the machine’s name. It is stored in two places:

File Used by
/etc/hostname Modern systems — single line with the hostname.
/etc/sysconfig/network (RHEL legacy) Contains HOSTNAME=....

Commands

hostname                          # show current hostname
hostname newname                  # set it (temporary, until reboot)

hostnamectl                       # systemd: show full info
hostnamectl set-hostname newname  # permanent: writes /etc/hostname

hostname alone changes it for the running system only. hostnamectl set-hostname writes the file too, making it persistent.


7. Name Resolution Configuration

/etc/hosts — static name-to-IP mapping

A plain text file that maps IP addresses to hostnames. Consulted before DNS on most systems.

127.0.0.1   localhost
127.0.1.1   myhost.localdomain myhost
192.168.1.50  fileserver fileserver.lan
::1         localhost ip6-localhost ip6-loopback

This file is the simplest way to add a name without setting up DNS.

/etc/resolv.conf — DNS resolver configuration

Tells the resolver which DNS servers to query.

nameserver 192.168.1.1
nameserver 8.8.8.8
search example.com lan
domain example.com
Keyword Meaning
nameserver IP A DNS server. List up to three; they’re tried in order.
search List of domain suffixes to append to single-label names. (ping webweb.example.com, then web.lan.)
domain Single default domain. Usually overridden by search.
options Tuning, e.g. options timeout:2 attempts:1.

Important caveat: on modern systems /etc/resolv.conf is often auto-generated by NetworkManager, systemd-resolved, or resolvconf. Edits may be overwritten. The right way to configure DNS depends on which system manages it.

/etc/nsswitch.conf — Name Service Switch

This file decides in what order different name databases are consulted. The relevant line for hostnames is hosts:.

hosts:    files dns

This means “check /etc/hosts first, then DNS.” Other databases the file can list include mdns4 (multicast DNS), nis, ldap. The passwd: and group: lines work the same way for user/group lookups.


8. Manual Interface Management at Runtime

These commands let you change networking right now without touching configuration files. The changes do not persist across reboots.

Modern: the ip command (from iproute2)

ip link                              # show interfaces (layer 2)
ip link set eth0 up
ip link set eth0 down

ip addr                              # show interface addresses (layer 3)
ip addr show eth0
ip addr add 192.168.1.10/24 dev eth0
ip addr del 192.168.1.10/24 dev eth0

ip route                             # show the routing table
ip route add default via 192.168.1.1
ip route add 10.0.0.0/8 via 192.168.1.254
ip route del default

ip -6 addr                           # IPv6 versions
ip -6 route

ip is the modern replacement for the older ifconfig, route, and arp commands.

Older equivalents (still on the exam)

ifconfig                             # show interfaces
ifconfig eth0 up
ifconfig eth0 192.168.1.10 netmask 255.255.255.0

route -n                             # show routing table
route add default gw 192.168.1.1
route del default

arp -n                               # show ARP cache (IPv4 to MAC)

These commands are provided by the net-tools package and are deprecated, but the exam still tests them.

ifup / ifdown

Bring an interface up or down using the configuration in /etc/network/interfaces (or NetworkManager, on systems that wrap them).

ifup eth0
ifdown eth0

9. DHCP Clients

When an interface is set to DHCP, a DHCP client runs in the background to obtain and renew the lease.

Common client programs:

You normally don’t run these by hand — they are started by your network-management system.


10. Quick Reference for the Exam

Files for persistent configuration:

Commands:


11. Likely Exam Questions (Self-Check)

  1. Which file holds the system’s hostname on a modern Linux system? /etc/hostname.

  2. What is the persistent way to set the hostname on a systemd system? hostnamectl set-hostname newname (it updates /etc/hostname).

  3. What is the difference between /etc/hosts and /etc/resolv.conf? /etc/hosts provides static name-to-IP mappings on the local machine. /etc/resolv.conf lists the DNS servers the resolver should query for names not in /etc/hosts.

  4. Which file controls the order of name lookups (hosts vs DNS)? /etc/nsswitch.conf, typically with hosts: files dns.

  5. On Debian, what is the main file for persistent network configuration? /etc/network/interfaces.

  6. On older Red Hat systems, where do per-interface config files live? /etc/sysconfig/network-scripts/ifcfg-<interface>.

  7. Which keyword in /etc/network/interfaces says “obtain settings via DHCP”? iface eth0 inet dhcp.

  8. What is the modern command-line tool for managing NetworkManager? nmcli (with nmtui as a curses UI).

  9. What is the modern replacement for ifconfig and route? The ip command from the iproute2 package: ip addr, ip link, ip route.

  10. How do you add an IP address to eth0 at runtime with ip? ip addr add 192.168.1.10/24 dev eth0.

  11. How do you add a default route at runtime with ip? ip route add default via 192.168.1.1.

  12. How do you bring eth0 up using configuration from /etc/network/interfaces? ifup eth0.

  13. In /etc/resolv.conf, what does the search directive do? Lists domain suffixes to append automatically to single-label hostnames (e.g. search example.com lets ping web resolve to web.example.com).

  14. What does BOOTPROTO=dhcp mean in a Red Hat ifcfg- file? The interface obtains its configuration via DHCP.

  15. What program typically runs in the background to handle DHCP on Linux? dhclient (the ISC DHCP client). Alternatives include dhcpcd and the built-in client in systemd-networkd.

  16. You edit /etc/resolv.conf directly and your changes are gone after reboot. Why? The file is auto-generated by NetworkManager, systemd-resolved, or resolvconf. Configure DNS through the tool that manages it (e.g. nmcli, the connection’s ipv4.dns, or the relevant config file).