Persistent network configuration
Configuring an interface so it survives a reboot: the modern ip commands, the files each distribution family uses, and the name resolution chain from /etc/hosts to DNS.
Lesson 2 of 4 in objective 109. Networking fundamentals, part of LPIC-1 Exam 102-500.
ip, and the commands it replaced
The iproute2 tools are the current ones. ip addr show lists addresses, ip addr add 192.168.1.10/24 dev eth0 assigns one, ip link set eth0 up brings an interface up, and ip route shows or sets routing — ip route add default via 192.168.1.1 sets a default gateway. Their predecessors, ifconfig, route and netstat, are deprecated but still appear in questions and still installed on plenty of machines; the equivalences are worth knowing in both directions. ss has replaced netstat for listing sockets: ss -tulpn shows listening TCP and UDP sockets with the process behind each.
Everything set with ip is lost at reboot. Persisting it depends on the family: Debian traditionally uses /etc/network/interfaces, Red Hat uses ifcfg files under /etc/sysconfig/network-scripts/, and both are increasingly replaced by NetworkManager (nmcli on the command line) or systemd-networkd. DHCP is the alternative to configuring anything, with a client requesting an address, mask, gateway and DNS servers from a server on the network.
The Debian file is worth being able to read and write, because it is short enough to be quoted whole in a question. It is a series of two-line stanzas: auto eth0 says bring this interface up at boot, and iface eth0 inet dhcp says how — inet for IPv4, then dhcp or static. A static stanza indents address, netmask and gateway lines underneath it. allow-hotplug is the alternative to auto and means "when the kernel says this interface appeared" rather than "at boot", which is what you want for a cable that may not be plugged in. Miss the auto line and the stanza is correct and never applied — ifup eth0 by hand would still work, and the machine would come up with no address.
Editing that file changes nothing on its own, and the way to apply it is the part candidates get wrong. ifup and ifdown are wrappers that read the stanzas and record which interfaces they have configured, historically under /run/network, and ifup refuses to touch an interface it believes is already up. So a changed address is applied by cycling the interface through the wrappers — ifdown eth0 && ifup eth0 — and NOT by ip link set eth0 down and up again, which toggles the link without ever re-reading the file. ifquery eth0 prints what ifup would apply, which is the safe way to check a stanza before committing to it.
The hostname is separate from any of this. hostname prints the running one and setting it that way lasts until reboot; the persistent name is in /etc/hostname. On a systemd machine hostnamectl set-hostname myserver does both at once — it writes the file and changes the running system — which is why it is the answer to a question that asks for a change that survives a reboot without saying which file.
in /etc/network/interfacesauto eth0iface eth0 inet dhcpor, for a fixed addressauto eth0iface eth0 inet static address 192.168.1.10/24 gateway 192.168.1.1hostnamectl set-hostname myservercat /etc/hostnamemyserver
systemd-networkd, the third place persistence can live
On a minimal server with neither ifupdown nor NetworkManager, the configuration is systemd-networkd's, and it reads three KINDS of file from /etc/systemd/network/, told apart by their extension: .link for udev-level device properties such as the name or MAC address, .netdev to CREATE a virtual device such as a bridge or a VLAN, and .network to configure addressing on an interface that already exists. Files are processed in lexicographic order of filename, which is why a numeric prefix is conventional, and the first .network file whose [Match] section matches an interface is the one applied.
So a static address is /etc/systemd/network/10-wired.network holding a [Match] section with Name=enp1s0 and a [Network] section with Address=10.0.0.10/24 and Gateway=10.0.0.1. For DHCP the [Network] section takes DHCP=yes in place of those two lines. Getting the extension wrong is the trap the distractors are built on: the same content in a .netdev or a .link file configures nothing, because neither of those is the file that assigns addresses.
networkctl is the client for the daemon, in the way nmcli is the client for NetworkManager. networkctl list gives the per-link summary and, crucially, says whether networkd has CONFIGURED each link or is leaving it unmanaged — a link showing unmanaged has no matching .network file. ip link show cannot answer that, because it reports the kernel's view of the interface and not who is looking after it. networkctl status enp1s0 expands one link with its addresses, routes and the .network file that matched, and networkctl reload picks up edited files.
Turning a name into an address
/etc/hosts is a static table of addresses and names, and it is consulted before DNS on a normally configured system — which makes it both the quick fix for a machine with no DNS entry and the reason a stale line there can override a correct DNS record. /etc/resolv.conf names the DNS servers to ask, with nameserver lines and a search list for unqualified names; on modern systems it is often generated by NetworkManager or systemd-resolved rather than edited.
/etc/nsswitch.conf is what decides the ORDER — the hosts line typically reads files dns, meaning /etc/hosts first and DNS second, and it is the file to point at when a question asks how the resolution order is configured. host and dig query DNS directly and therefore ignore /etc/hosts entirely, while getent hosts goes through the full name service and does not. That difference is the fastest way to prove which layer is answering.
Worth carrying in
- ip addr add … dev eth0
- Assign an address.
ip addr showlists them. - ip link set eth0 up
- Bring an interface up or down.
- ip route add default via …
- Set the default gateway.
- ss -tulpn
- Listening TCP and UDP sockets with the owning process. Replaces netstat.
- /etc/network/interfaces
- Debian persistent configuration:
auto eth0theniface eth0 inet dhcp. Red Hat uses/etc/sysconfig/network-scripts/. - ifdown eth0 && ifup eth0
- Apply an edited
/etc/network/interfacesstanza. Toggling the link withipdoes not re-read it. - /etc/systemd/network/10-wired.network
[Match]names the interface,[Network]the address..netdevcreates devices,.linksets properties.- networkctl list
- Per-link state under systemd-networkd, including which links it is leaving unmanaged.
- nmcli
- NetworkManager on the command line.
- hostnamectl set-hostname
- Change the running hostname AND
/etc/hostnamein one command. - /etc/hosts
- Static name-to-address table, consulted before DNS.
- /etc/resolv.conf
- nameserver and search lines. Often generated, not hand-edited.
- /etc/nsswitch.conf
- Decides the lookup ORDER — files then dns, typically.
What the exam does with this
ipcommands do not survive a reboot. Persistence is a file, and which file depends on the distribution.digand host ask DNS directly and ignore/etc/hosts;getentdoes not. Expect that as a troubleshooting question.nsswitch.confsets the order,resolv.confsets the servers. They are different questions.- A stanza with no
autoline is never brought up at boot, however correct the rest of it is. hostname myserverlasts until reboot;hostnamectl set-hostname myserverwrites/etc/hostnametoo.
- Objective
- 109. Networking fundamentals
- Share of the exam
- 23.33% (the whole objective)
- Questions in this lesson
- 20
- Signed for by a person
- 0
Partly checked. None of the 20 questions here has been read against the cited source by a person. 20 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.
Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.
How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.
Drill this lesson
A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.
Practise Persistent network configuration
Questions in this lesson
- /etc/nsswitch.conf contains the line `hosts: dns files`, and /etc/hosts maps db.example.com to 10.0.0.5 while public DNS returns 203.0.113.9 for the same name. What does an application using the standard resolver library get? machine-checked
- You want to ask the specific name server 8.8.8.8 for the MX records of example.com, bypassing whatever is configured in /etc/resolv.conf. Which command does this? machine-checked
- An entry for buildhost in /etc/hosts is being ignored by dig, which keeps returning NXDOMAIN. Which command resolves the name the same way an ordinary application would, so you can confirm the /etc/hosts entry is effective? machine-checked
- On a Debian system using the traditional ifupdown scheme, which stanza in /etc/network/interfaces brings up eth0 at boot with an address obtained from a DHCP server? machine-checked
- On a systemd system, which command sets the static hostname persistently by writing it to /etc/hostname and applying it to the running system at once? machine-checked
- Which three commands display the system's routing table, including the default gateway? (Choose three.) machine-checked
- Give the absolute path of the file that traditionally lists the DNS servers the local resolver library should query. machine-checked
- You have changed a setting on the NetworkManager profile named lan-static with `nmcli connection modify lan-static ipv4.dns 10.0.0.53`, but resolution still uses the old server. Which command applies the stored profile to the running interface without restarting the NetworkManager service? machine-checked
- A server currently gets its address by DHCP through the NetworkManager profile office. It must instead keep the fixed address 192.0.2.50/24 with gateway 192.0.2.1 across reboots. Which command line configures the profile correctly? machine-checked
- A laptop running NetworkManager has never connected to the wireless network cafe-guest, which is protected by the passphrase Sunflower9. Which command joins it and creates a profile for future use? machine-checked
- On a workstation whose interfaces are managed by NetworkManager, which two approaches make an address change survive a reboot? (Choose two.) machine-checked
- Before boarding a flight you want to switch off the wireless radio with nmcli, leaving the wired connection working. Which command does that? machine-checked
- You are adding a local entry so that the names printsrv.example.com and printsrv both resolve to 10.20.0.9 without DNS. Which line has the correct /etc/hosts syntax? machine-checked
- A system running systemd-resolved carries the line `hosts: resolve [!UNAVAIL=return] files dns` in /etc/nsswitch.conf. What is the effect of the bracketed action? machine-checked
- Users type short names such as `wiki` and `build`, and the resolver must try them in corp.example.com first and lab.example.com second. Which /etc/resolv.conf directive expresses that? machine-checked
- A minimal server uses systemd-networkd. Which file and content give interface enp1s0 the static address 10.0.0.10/24 with gateway 10.0.0.1? machine-checked
- On a host using systemd-networkd you need to see, for every link, whether networkd has actually configured it or is leaving it unmanaged. Which command reports that? machine-checked
- On a Debian host using the traditional ifupdown scheme you have edited the static address of eth0 in /etc/network/interfaces. The interface is currently up with the old address. Which command sequence puts the new settings into effect? machine-checked
- Type the command that reports a systemd system's hostname settings — static, and pretty or transient where they differ — together with its machine ID, operating system and kernel version. machine-checked
- Type the nmcli command, in full and without abbreviating any word, that lists the wireless access points NetworkManager can currently see. machine-checked
Practise Persistent network configuration
The rest of objective 109
- Internet protocol fundamentals
- Persistent network configuration — you are here
- Troubleshooting a network connection
- Client side DNS