Networking Configuration
Networking Configuration
Networking is the circulatory system of every production server. A misconfigured interface, a wrong DNS resolver, or an unexpected routing table entry will take down services silently — no crash, no core dump, just unreachable endpoints at 3 AM. This lesson gives you the full mental model and hands-on command set that senior DevOps engineers use to configure, inspect, and debug Linux networking on bare metal, VMs, and cloud instances.
The ip Command: Your Primary Tool
The ip command from the iproute2 package is the modern replacement for the long-deprecated ifconfig, route, and arp. Every major distribution ships it; every cloud provider's stock images have it. Do not use ifconfig — it hides secondary addresses, ignores modern routing tables, and is simply not installed on minimal images anymore.
The ip command uses a consistent object-verb grammar: ip <object> <verb>. The primary objects are link (layer 2 interfaces), addr (IP addresses), route (routing table), and neigh (ARP/NDP cache).
ip route get: When a service cannot reach a remote endpoint, run ip route get <remote-ip> before anything else. It tells you exactly which source IP and interface Linux will use for that destination. At large companies with multiple NICs, routing table asymmetry is a common and easy-to-miss failure mode.
Understanding Network Interfaces
On a modern Linux server you will encounter several types of network interfaces:
- Physical NICs: named by predictable network interface names (PNI) — e.g.
eno1(on-board),enp3s0(PCI bus/slot),ens3(hot-plug slot). PNI was introduced to eliminate the oldeth0/eth1naming, which was non-deterministic across reboots on multi-NIC servers. - Virtual/cloud NICs: AWS names them
ens3/eth0; GCP names themens4. The exact name depends on the hypervisor and kernel driver. - Loopback:
lo— always127.0.0.1/8. Services binding to127.0.0.1are only reachable locally. - Docker/container bridges:
docker0,cni0,br-xxxx— virtual bridges created by container runtimes. - Bonding/teaming: two or more physical NICs merged into one logical interface for redundancy or bandwidth aggregation.
- VLANs: tagged sub-interfaces, e.g.
eth0.100.
ip link show, look for the flags in the angle brackets: UP means the interface is administratively enabled; LOWER_UP means physical carrier is detected (cable plugged in or wireless associated). A flapping NIC shows UP but alternating LOWER_UP/NO-CARRIER — a hardware or cable problem, not a software one.
Persistent Configuration: Netplan and NetworkManager
Changes made with ip are ephemeral — they vanish on reboot. Persistent network configuration is managed by one of two stacks depending on your distribution:
- Netplan (Ubuntu 17.10+, default on Ubuntu Server) — YAML declarations in
/etc/netplan/; Netplan generates config for a back-end renderer (eithernetworkdor NetworkManager) and applies it. - NetworkManager (Red Hat/CentOS/Fedora, and optionally Ubuntu Desktop) — managed via
nmcli,nmtui, or connection profiles in/etc/NetworkManager/system-connections/.
Netplan example — a server with a static IP on one interface and DHCP on another:
NetworkManager via nmcli — the command-line approach preferred in automation:
Hostnames and DNS Resolution
Name resolution in Linux flows through a layered resolver chain. Understanding the chain is essential for debugging service discovery failures in production:
/etc/hosts— static table, checked first by default. Useful for local overrides and container hostnames, but a maintenance nightmare at scale.- NSS (Name Service Switch) — configured in
/etc/nsswitch.conf. Thehosts:line controls resolution order, typicallyfiles dns myhostname. - DNS resolver — queries the nameservers listed in
/etc/resolv.conf. On modern systems this file is managed bysystemd-resolvedand is a symlink to/run/systemd/resolve/stub-resolv.conf.
systemd-resolved and the stub resolver: On Ubuntu 18.04+ and modern RHEL systems, /etc/resolv.conf points to 127.0.0.53:53, the stub resolver run by systemd-resolved. This gives you per-interface DNS, DNSSEC, and caching. If you replace /etc/resolv.conf with a plain file pointing to a corporate DNS server, you lose all of that. The correct way to configure DNS is through Netplan (nameservers:) or nmcli so that systemd-resolved learns about it per-interface.
Putting It Together: Diagnosing a Network Failure
When a service is unreachable, work through this mental model layer by layer:
- Is the interface up?
ip link show <if>— look forLOWER_UP. - Does it have the right IP?
ip addr show <if>. - Is the route correct?
ip route get <destination>. - Does ARP/L2 work?
ip neigh show— is the gateway MAC resolved? - Does DNS resolve?
dig <hostname>— compare withdig @8.8.8.8 <hostname>to isolate local resolver issues. - Is the port open?
ss -tulnp | grep <port>on the server;nc -zv <host> <port>from the client. - Is a firewall blocking?
iptables -L -n -vornft list ruleset— covered in the Security Hardening lesson.
ss over netstat: netstat is deprecated and often not installed on minimal images. ss (socket statistics) is faster, always present, and shows the owning process via -p. The flags -tulnp mean: TCP + UDP, Listening only, Numeric (no DNS), with Process. Memorise this combination — you will run it many times per day.