Home Blog Certs Knowledge Base About

LPIC-1 109.2 โ€” Persistent Network Configuration

Exam weight: 4 โ€” LPIC-1 v5, Exam 102

What You Need to Know

From the official LPIC-1 objectives:

  • Understand basic TCP/IP host configuration.
  • Configure Ethernet and Wi-Fi network using NetworkManager.
  • Awareness of systemd-networkd.

Key files and commands: /etc/hostname, /etc/hosts, /etc/nsswitch.conf, /etc/resolv.conf, /etc/network/interfaces, ifup, ifdown, ip, ifconfig, route, nmcli, hostnamectl.


Network Interface Naming

Naming Prefixes

PrefixInterface type
enEthernet
ibInfiniBand
slSerial line (SLIP)
wlWireless LAN
wwWireless WAN (WWAN)

Naming Policies (predictable names)

The kernel assigns names in order of priority:

  1. BIOS onboard index โ€” eno1, eno2
  2. PCI slot number โ€” ens1, ens3
  3. Bus topology (PCI bus/slot/function) โ€” enp2s0
  4. MAC address โ€” enx001122334455
  5. Legacy โ€” eth0, eth1 (fallback)

Listing Interfaces

ip link show          # modern
ifconfig -a           # all interfaces, including inactive
nmcli device          # NetworkManager device list

/etc/network/interfaces (Debian/Ubuntu)

The traditional network configuration file used with ifupdown.

# Loopback
auto lo
iface lo inet loopback

# DHCP
auto eth0
iface eth0 inet dhcp

# Static
auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4

Key directives:

DirectiveDescription
auto IFACEBring up interface at boot
iface IFACE inet dhcpConfigure via DHCP
iface IFACE inet staticStatic configuration
addressIP address
netmaskSubnet mask
gatewayDefault gateway
dns-nameserversDNS servers (requires resolvconf)

ifup / ifdown

ifup eth0      # bring up interface
ifdown eth0    # bring down interface

Hostname Configuration

/etc/hostname

Contains the system’s static hostname as a single line:

myserver

hostnamectl

hostnamectl                          # show current hostname info
hostnamectl set-hostname myserver    # set static hostname
hostnamectl set-hostname "My Server" --pretty   # set pretty hostname
hostnamectl set-hostname "" --transient          # set transient hostname
hostnamectl status                   # show all hostname types

Three hostname types:

TypeDescription
StaticStored in /etc/hostname; persists across reboots
TransientSet by the kernel or DHCP; lost on reboot
PrettyFree-form human-readable label

Name Resolution Files

/etc/nsswitch.conf

Controls the order and sources for name resolution. The hosts line determines how hostnames are resolved:

hosts:    files dns

This checks /etc/hosts first, then DNS.

/etc/hosts

Maps IP addresses to hostnames locally, bypassing DNS:

127.0.0.1       localhost
127.0.1.1       myserver
::1             localhost ip6-localhost ip6-loopback
192.168.1.10    fileserver fs

Format: IP ADDRESS hostname [alias ...]

/etc/resolv.conf

Configures DNS servers and search domains:

nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
DirectiveDescription
nameserver IPDNS server (up to 3)
search DOMAINAppend domain for unqualified lookups (up to 6)
domain DOMAINLocal domain (mutually exclusive with search)

Note: NetworkManager and other tools may overwrite this file automatically.


NetworkManager and nmcli

NetworkManager is the standard network management daemon on most distributions. nmcli is its command-line client.

nmcli Object Overview

ObjectDescription
generalOverall NetworkManager status
networkingEnable/disable networking
radioWi-Fi and WWAN radio switches
connectionManage saved connections
deviceManage network interfaces
agentSecret agents
monitorMonitor network activity

Common nmcli Commands

# Status
nmcli general status
nmcli device status
nmcli device show eth0

# Connections
nmcli connection show
nmcli connection up myconn
nmcli connection down myconn
nmcli connection delete myconn

# Add a static Ethernet connection
nmcli connection add type ethernet ifname eth0 con-name myconn \
  ipv4.addresses 192.168.1.100/24 \
  ipv4.gateway 192.168.1.1 \
  ipv4.dns 8.8.8.8 \
  ipv4.method manual

# Modify an existing connection
nmcli connection modify myconn ipv4.dns 1.1.1.1

# Networking on/off
nmcli networking on
nmcli networking off

# Wi-Fi
nmcli radio wifi on
nmcli device wifi list
nmcli device wifi connect "MySSID" password "MyPass"

systemd-networkd

systemd-networkd is a systemd-based network configuration daemon.

Configuration Directories

PathDescription
/lib/systemd/network/Shipped by packages
/run/systemd/network/Runtime (generated)
/etc/systemd/network/Administrator configuration (highest priority)

.network File Format

Files must end in .network. The [Match] section selects the interface; [Network] sets the configuration.

# DHCP example: /etc/systemd/network/10-eth0.network
[Match]
Name=eth0

[Network]
DHCP=yes
# Static example
[Match]
Name=eth0

[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8

Quick Reference

Interface prefixes: en (Ethernet)  wl (Wi-Fi)  ww (WWAN)
  eno1 (onboard)  ens1 (PCI slot)  enp2s0 (bus)  enx... (MAC)

ip link show         list interfaces
ifconfig -a          all interfaces (legacy)
nmcli device         NetworkManager device list

/etc/network/interfaces:
  auto IFACE           bring up at boot
  iface IFACE inet dhcp/static/loopback
  address / netmask / gateway / dns-nameservers
  ifup IFACE / ifdown IFACE

Hostname:
  /etc/hostname          static hostname file
  hostnamectl set-hostname NAME   set static
  hostnamectl status              show all types

Name resolution:
  /etc/nsswitch.conf    hosts: files dns
  /etc/hosts            IP hostname [alias]
  /etc/resolv.conf      nameserver / search / domain

nmcli:
  nmcli general status
  nmcli connection show/add/modify/up/down/delete
  nmcli device status/show/wifi list
  nmcli device wifi connect SSID password PASS

systemd-networkd .network file:
  [Match] Name=eth0
  [Network] DHCP=yes  or  Address=.../24  Gateway=...  DNS=...
  Config dir: /etc/systemd/network/

Exam Questions

  1. What prefix identifies a wireless LAN interface? โ†’ wl
  2. What naming convention produces interface names like enp2s0? โ†’ PCI bus topology (bus/slot/function)
  3. What directive in /etc/network/interfaces brings an interface up automatically at boot? โ†’ auto IFACE
  4. What command brings down interface eth0 in the ifupdown system? โ†’ ifdown eth0
  5. Where is the static hostname stored? โ†’ /etc/hostname
  6. What hostnamectl command sets the static hostname to webserver? โ†’ hostnamectl set-hostname webserver
  7. What are the three hostname types managed by hostnamectl? โ†’ Static, transient, and pretty.
  8. What file controls the order in which name resolution sources are consulted? โ†’ /etc/nsswitch.conf
  9. What is the format of an /etc/hosts entry? โ†’ IP_ADDRESS hostname [alias ...]
  10. How many nameserver entries can /etc/resolv.conf hold? โ†’ Up to 3.
  11. What is the difference between search and domain in /etc/resolv.conf? โ†’ They are mutually exclusive; if both are present, the last one wins.
  12. What nmcli command shows all saved connections? โ†’ nmcli connection show
  13. What nmcli command connects to a Wi-Fi network named Office? โ†’ nmcli device wifi connect "Office" password "pass"
  14. What nmcli object is used to manage network interfaces? โ†’ device
  15. In which directory does a system administrator place systemd-networkd configuration files? โ†’ /etc/systemd/network/
  16. What section in a .network file selects the interface to configure? โ†’ [Match]
  17. What nmcli command disables all networking? โ†’ nmcli networking off
  18. What tool may overwrite /etc/resolv.conf automatically? โ†’ NetworkManager (indicated by a comment # Generated by NetworkManager in the file).

Exercises

Exercise 1 โ€” Static Interface Configuration

Write an /etc/network/interfaces stanza that configures eth1 statically with IP 10.0.0.50/24, gateway 10.0.0.1, and DNS 10.0.0.53.

Answer
auto eth1
iface eth1 inet static
    address 10.0.0.50
    netmask 255.255.255.0
    gateway 10.0.0.1
    dns-nameservers 10.0.0.53

Exercise 2 โ€” Hostname Change

Change the system’s static hostname to dbserver using hostnamectl, then verify the change.

Answer
hostnamectl set-hostname dbserver
hostnamectl status

Exercise 3 โ€” nmcli Static Connection

Use nmcli to create a static Ethernet connection named corp on eth0 with IP 192.168.10.20/24, gateway 192.168.10.1, and DNS 192.168.10.5.

Answer
nmcli connection add type ethernet ifname eth0 con-name corp \
  ipv4.addresses 192.168.10.20/24 \
  ipv4.gateway 192.168.10.1 \
  ipv4.dns 192.168.10.5 \
  ipv4.method manual
nmcli connection up corp

Exercise 4 โ€” systemd-networkd

Write a systemd-networkd configuration file that enables DHCP on interface ens3.

Answer

Create /etc/systemd/network/10-ens3.network:

[Match]
Name=ens3

[Network]
DHCP=yes

Exercise 5 โ€” nsswitch.conf

Modify the hosts line in /etc/nsswitch.conf so that /etc/hosts is checked first, and DNS is only consulted if the host is not found there.

Answer
hosts:    files dns

With files listed first, /etc/hosts is checked before DNS. If the entry is found in files, DNS is not queried.


LPIC-1 Study Notes | Topic 109: Networking Fundamentals