Welcome to the fourth part of our technical wiki series on Linux administration!
After we covered the fundamentals of system administration, user management, and process management in previous articles, we now turn to network configuration and management.
As a Linux administrator, it is important to understand how networks work and how you configure them. Think of a network like a postal system: Every computer has its own IP address, and the network configuration determines how packets are exchanged between computers.
⚠️ Note: In this article, we use Ubuntu/Debian as the example distribution. The basic concepts are the same on all Linux systems, but package installation and some configuration paths may vary depending on the distribution. If you use a different distribution, please consult the relevant documentation for the specific installation commands and paths.
What is a Network?
A network connects computers and enables data exchange. In Linux, there are various tools and concepts to help you with network management.
Network fundamentals:
┌─────────── Physical Layer ──────────────────────────────────┐
│ • Network interfaces │
│ • Cables and connections │
│ • Hardware addresses (MAC) │
├─────────── Logical Layer ───────────────────────────────────┤
│ • IP addresses │
│ • Routing │
│ • DNS and name resolution │
└─────────────────────────────────────────────────────────────┘
Understanding Network Fundamentals
In Linux systems, the network is divided into different layers. Let's examine these layers in detail:
Physical Layer
Physical network components:
┌─────────── Hardware ────────────────────────────────────────┐
│ • Network interfaces (eth0, wlan0) │
│ • Cable connections │
│ • MAC addresses │
├─────────── Management ──────────────────────────────────────┤
│ • Drivers and modules │
│ • Speed/duplex │
│ • Connection status │
└─────────────────────────────────────────────────────────────┘
# Display network interfaces
ip link show
# or traditional
ifconfig -a
# Check MAC address and status
ip link show eth0
# Shows:
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP>
link/ether 00:11:22:33:44:55
Logical Layer
Logical network configuration:
┌─────────── Addressing ──────────────────────────────────────┐
│ • IP addresses (IPv4/IPv6) │
│ • Subnet masks │
│ • Gateway configuration │
├─────────── Name Resolution ─────────────────────────────────┤
│ • DNS servers │
│ • Hostname │
│ • /etc/hosts │
└─────────────────────────────────────────────────────────────┘
Understanding the Logical Network Layer
IP Addressing
An IP address is like a postal address for your computer. In IPv4, it consists of four numbers between 0 and 255:
IP addressing:
┌─────────── IPv4 ────────────────────────────────────────────┐
│ • Format: xxx.xxx.xxx.xxx │
│ • Example: 192.168.1.100 │
│ • Subnet mask: 255.255.255.0 │
├─────────── Ranges ──────────────────────────────────────────┤
│ • Private: 192.168.0.0/16 │
│ • Private: 10.0.0.0/8 │
│ • Private: 172.16.0.0/12 │
└─────────────────────────────────────────────────────────────┘
The IP address is divided into network and host parts:
192.168.1.0is the network.100is the host in this network- The subnet mask
255.255.255.0separates these areas
DNS (Domain Name System)
DNS translates domain names into IP addresses, similar to how a telephone directory translates names into numbers:
DNS resolution:
┌─────────── Process ─────────────────────────────────────────┐
│ 1. Request: www.example.com │
│ 2. Query DNS server │
│ 3. Receive IP: 93.184.216.34 │
├─────────── Configuration ───────────────────────────────────┤
│ • /etc/hosts for local names │
│ • /etc/resolv.conf for DNS │
│ • NetworkManager settings │
└─────────────────────────────────────────────────────────────┘
DNS Resolution in Detail
DNS resolution in Linux follows a specific process, similar to a telephone directory that searches through various directories sequentially.
DNS Resolution Process
DNS resolution process:
┌─────────── Client Request ──────────────────────────────────┐
│ 1. Browser requests www.example.com │
│ 2. System checks local DNS cache │
│ 3. System checks /etc/hosts │
├─────────── DNS Server ──────────────────────────────────────┤
│ 4. Request to configured DNS │
│ 5. DNS queries root server │
│ 6. DNS queries TLD server (.com) │
│ 7. DNS queries authoritative server │
└─────────────────────────────────────────────────────────────┘
DNS Configuration in Linux
DNS configuration is mainly done via two files:
# 1. /etc/resolv.conf - DNS server configuration
nameserver 8.8.8.8 # Google DNS
nameserver 8.8.4.4 # Google DNS backup
search example.com # Local domain search
domain example.com # Local domain
# 2. /etc/hosts - Local DNS entries
127.0.0.1 localhost
192.168.1.10 server1.local server1
DNS Query Tools
DNS tools overview:
┌─────────── dig ─────────────────────────────────────────────┐
│ • Detailed DNS queries │
│ • Various record types │
│ • Query specific nameservers │
├─────────── nslookup ────────────────────────────────────────┤
│ • Simple DNS queries │
│ • Interactive mode │
│ • Reverse lookups │
├─────────── host ────────────────────────────────────────────┤
│ • Quick, simple queries │
│ • IP to name and vice versa │
│ • Basic DNS information │
└─────────────────────────────────────────────────────────────┘
# Example with dig
dig example.com
# Shows A record (IPv4)
# Example with nslookup
nslookup example.com
# Shows name and IP
# Example with host
host example.com
# Shows simplified DNS information
DNS Troubleshooting in Practice
DNS troubleshooting tools:
┌─────────── Diagnosis ───────────────────────────────────────┐
│ • ping (reachability) │
│ • dig (DNS queries) │
│ • nslookup (name resolution) │
├─────────── Logs ────────────────────────────────────────────┤
│ • /var/log/syslog │
│ • /var/log/messages │
│ • dmesg │
└─────────────────────────────────────────────────────────────┘
# 1. Check basic connectivity
ping 8.8.8.8
ping google.com
# 2. Test DNS resolution
dig google.com
nslookup google.com
# 3. Check DNS server
cat /etc/resolv.conf
Understanding Routing
Routing in Linux determines how network packets find their way through the network. Think of routing like a navigation system:
Routing concepts:
┌─────────── Default Route ───────────────────────────────────┐
│ • Default Gateway │
│ • Path to the Internet │
│ • Fallback for unknown destinations │
├─────────── Static Routes ───────────────────────────────────┤
│ • Manually configured paths │
│ • Direct connections │
│ • Specific networks │
└─────────────────────────────────────────────────────────────┘
Understanding the Routing Table
# Display routing table
ip route show
# or traditional
route -n
Example output:
- default via 192.168.1.1 dev eth0
- 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100
Configuring Routes
# Set default gateway
ip route add default via 192.168.1.1
# Add specific route
ip route add 10.0.0.0/24 via 192.168.1.254
# Delete route
ip route del 10.0.0.0/24
Network Configuration
After the fundamentals, we now turn to the practical configuration of your network. In Linux, there are various tools and methods for making network settings:
Network configuration:
┌─────────── Interfaces ──────────────────────────────────────┐
│ • Assign IP addresses │
│ • Set subnet masks │
│ • Configure gateway │
├─────────── DNS ─────────────────────────────────────────────┤
│ • Set nameservers │
│ • Configure hostname │
│ • Define domains │
└─────────────────────────────────────────────────────────────┘
Interface Configuration
Assign IP address
- sudo ip addr add 192.168.1.100/24 dev eth0
Set gateway
sudo ip route add default via 192.168.1.1
# Check changes
ip addr show eth0
ip route show
Configuring DNS Servers
DNS configuration is mainly done via three important files:
DNS configuration files:
┌─────────── /etc/resolv.conf ────────────────────────────────┐
│ • DNS server addresses │
│ • Search domains │
│ • DNS options │
├─────────── /etc/hosts ──────────────────────────────────────┤
│ • Local DNS entries │
│ • Hostname-IP mappings │
│ • Static entries │
├─────────── /etc/nsswitch.conf ──────────────────────────────┤
│ • Name resolution order │
│ • DNS priorities │
└─────────────────────────────────────────────────────────────┘
Configure DNS servers in /etc/resolv.conf
nameserver 8.8.8.8 # Google DNS (primary)
nameserver 8.8.4.4 # Google DNS (secondary)
nameserver 192.168.1.1 # Router/local DNS
search local.domain # Local search domain
domain local.domain # Default domain
Define local hosts in /etc/hosts
- 127.0.0.1 localhost
- 192.168.1.10 server1.local server1
- 192.168.1.11 server2.local server2
DNS resolution order in /etc/nsswitch.conf
- hosts: files dns
Network Security
Securing your network is an important task in Linux administration. Here we learn the fundamental security concepts:
Network security:
┌─────────── Firewall ────────────────────────────────────────┐
│ • Open/close ports │
│ • Define rules │
│ • Access control │
├─────────── SSH ─────────────────────────────────────────────┤
│ • Secure connections │
│ • Key management │
│ • Access restrictions │
└─────────────────────────────────────────────────────────────┘
Firewall Configuration
The Linux firewall (iptables/nftables) is your first line of defense against unwanted network access. Let's understand how it works:
Firewall fundamentals:
┌─────────── Inbound ─────────────────────────────────────────┐
│ • Connections from outside │
│ • Port access │
│ • Service requests │
├─────────── Outbound ────────────────────────────────────────┤
│ • Connections to outside │
│ • Updates & downloads │
│ • Service responses │
└─────────────────────────────────────────────────────────────┘
UFW (Uncomplicated Firewall)
# Enable UFW
sudo ufw enable
# Set default rules
sudo ufw default deny incoming
sudo ufw default allow outgoing
# Open ports
sudo ufw allow 22/tcp # SSH
sudo ufw allow 80/tcp # HTTP
sudo ufw allow 443/tcp # HTTPS
# Check status
sudo ufw status verbose
Advanced Firewall Rules
UFW (Uncomplicated Firewall)
Advanced UFW rules:
┌─────────── Port Ranges ─────────────────────────────────────┐
│ • Open/close ports │
│ • Define port ranges │
│ • Set protocols │
├─────────── IP Addresses ────────────────────────────────────┤
│ • Allow/block individual IPs │
│ • Manage networks │
│ • Subnet rules │
└─────────────────────────────────────────────────────────────┘
# Define port ranges
sudo ufw allow 3000:4000/tcp # Port range
sudo ufw allow 80,443/tcp # Multiple ports
# IP-based rules
sudo ufw allow from 192.168.1.0/24 # Subnet
sudo ufw deny from 10.0.0.5 # Individual IP
IPtables (Classic Firewall)
IPtables structure:
┌─────────── Chains ──────────────────────────────────────────┐
│ • INPUT (inbound) │
│ • OUTPUT (outbound) │
│ • FORWARD (forwarded) │
├─────────── Actions ─────────────────────────────────────────┤
│ • ACCEPT (allow) │
│ • DROP (discard) │
│ • REJECT (reject) │
└─────────────────────────────────────────────────────────────┘
Practical Examples for IPtables
IPtables is a powerful tool for firewall configuration. Here are the most important use cases:
IPtables basic rules:
┌─────────── Inbound ─────────────────────────────────────────┐
│ • SSH (Port 22) │
│ • Web (Port 80/443) │
│ • DNS (Port 53) │
├─────────── Outbound ────────────────────────────────────────┤
│ • Updates and downloads │
│ • DNS requests │
│ • Web access │
└─────────────────────────────────────────────────────────────┘
Basic Configuration
# Delete all existing rules
iptables -F
# Set default policies
iptables -P INPUT DROP # Block everything
iptables -P FORWARD DROP # No routing
iptables -P OUTPUT ACCEPT # Allow outbound
# Allow loopback
iptables -A INPUT -i lo -j ACCEPT
Allow Important Services
# Allow SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow web server
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Allow existing connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
nftables
nftables is the modern successor to iptables. Here are the most important concepts and configurations:
nftables structure:
┌─────────── Tables ──────────────────────────────────────────┐
│ • filter (packet filtering) │
│ • nat (address translation) │
│ • mangle (packet modification) │
├─────────── Chains ──────────────────────────────────────────┤
│ • input (inbound) │
│ • output (outbound) │
│ • forward (forwarded) │
└─────────────────────────────────────────────────────────────┘
Basic Configuration
# Create new table
nft add table inet firewall
# Create base chain
nft add chain inet firewall input { type filter hook input priority 0 \; }
nft add chain inet firewall output { type filter hook output priority 0 \; }
# Set basic rules
nft add rule inet firewall input ct state established,related accept
nft add rule inet firewall input ct state invalid drop
Practical Examples
# Allow SSH
nft add rule inet firewall input tcp dport 22 accept
# Allow HTTP/HTTPS
nft add rule inet firewall input tcp dport { 80, 443 } accept
# Display rules
nft list ruleset
SSH Security
SSH (Secure Shell) is an important tool for secure remote administration of your system. Let's look at the most important security aspects:
SSH security:
┌─────────── Authentication ──────────────────────────────────┐
│ • Password vs. keys │
│ • Public/Private key pairs │
│ • SSH-Agent │
├─────────── Configuration ───────────────────────────────────┤
│ • Change port │
│ • Disable root login │
│ • Protocol version │
└─────────────────────────────────────────────────────────────┘
SSH Configuration in Detail
SSH (Secure Shell) is an important tool for secure remote administration. Let's go through the most important configuration aspects:
SSH configuration:
┌─────────── Server ──────────────────────────────────────────┐
│ • Port and binding │
│ • Authentication │
│ • Access control │
├─────────── Client ──────────────────────────────────────────┤
│ • Key management │
│ • Connection options │
│ • Known Hosts │
└─────────────────────────────────────────────────────────────┘
Server Configuration (/etc/ssh/sshd_config)
# Basic security settings
Port 22 # Standard SSH port
PermitRootLogin no # Forbid root login
PasswordAuthentication no # Only allow keys
MaxAuthTries 3 # Maximum login attempts
# Restart service after changes
sudo systemctl restart sshd
Key-based Authentication
# Create key pair
ssh-keygen -t ed25519 -C "server1"
# Copy public key to server
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server
# Check permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
Advanced SSH Security Settings
Securing your SSH server is crucial for system security. Here are the most important advanced settings:
SSH security options:
┌─────────── Access Control ──────────────────────────────────┐
│ • Allowed/forbidden users │
│ • IP-based restrictions │
│ • Time-based restrictions │
├─────────── Encryption ──────────────────────────────────────┤
│ • Key algorithms │
│ • Cipher suites │
│ • MAC algorithms │
└─────────────────────────────────────────────────────────────┘
Advanced sshd_config Settings
# /etc/ssh/sshd_config
# Security settings
AllowUsers anna bob # Only specific users
PermitRootLogin no # Forbid root login
MaxAuthTries 3 # Maximum login attempts
LoginGraceTime 30 # Time limit for login
# Encryption options
Ciphers aes256-ctr,aes192-ctr
MACs hmac-sha2-512,hmac-sha2-256
KexAlgorithms curve25519-sha256
Network Monitoring
Monitoring your network is essential for stable operation. Here are the most important tools and concepts.
Installing Monitoring Tools
sudo apt install net-tools # for netstat
sudo apt install iproute2 # for ss
sudo apt install iftop # for interface monitoring
sudo apt install nethogs # for process monitoring
sudo apt install iptraf-ng # for detailed network analysis
Monitoring tools in practice:
┌─────────── Traffic Monitor ─────────────────────────────────┐
│ nethogs: Process-based │
│ iftop: Interface-based │
│ iptraf: Detailed statistics │
├─────────── Output Examples ─────────────────────────────────┤
│ nethogs: PID USER PROGRAM KB/s │
│ iftop: SOURCE <-> DEST KB/s │
│ iptraf: PORTS, PROTOCOLS │
└─────────────────────────────────────────────────────────────┘
Traffic Monitoring
# Process-based monitoring
sudo nethogs eth0
# Interface-based monitoring
sudo iftop -i eth0
# Bandwidth monitoring
nload eth0
Connection Monitoring
# Display active connections
ss -tuln
# Check open ports
netstat -tulpn
# Processes with network connections
lsof -i
Monitoring Tools in Practice
Bandwidth Monitoring with nload
nload eth0
# Shows:
Incoming: ▁▂▃▅█▇ 2.5 MB/s
Outgoing: ▁▁▂▃▂▁ 1.2 MB/s
Process-based Monitoring with nethogs
sudo nethogs eth0
# Shows:
PID USER PROGRAM SENT RECEIVED
1234 anna firefox 2.5KB/s 15.4KB/s
5678 bob wget 0.1KB/s 350.2KB/s
Interface Statistics with iftop
sudo iftop -i eth0
# Shows:
Source Destination Transfer
192.168.1.100:443 10.0.0.5:52431 1.2Mb 2.5Mb
Long-term Monitoring
Collecting Traffic Statistics
vnstat -i eth0
# Shows:
heute: 15.24 GB / 25.31 GB / 40.55 GB
gestern: 12.54 GB / 22.35 GB / 34.89 GB
dieser Monat: 345.45 GB / 678.12 GB / 1.02 TB
Graphical Evaluation with vnstati
- vnstati -s -i eth0 -o summary.png
Troubleshooting
When network problems occur, a systematic approach helps with troubleshooting:
Troubleshooting steps:
┌─────────── Connection ──────────────────────────────────────┐
│ • ping (reachability) │
│ • traceroute (routing path) │
│ • netstat (connections) │
├─────────── DNS ─────────────────────────────────────────────┤
│ • nslookup (name resolution) │
│ • dig (detailed DNS info) │
│ • Check /etc/resolv.conf │
├─────────── Logs ────────────────────────────────────────────┤
│ • dmesg (kernel messages) │
│ • /var/log/syslog │
│ • journalctl │
└─────────────────────────────────────────────────────────────┘
Practical Troubleshooting
Basic Connectivity
ping 8.8.8.8 # Internet connection
ping gateway # Router reachable
ip route show # Routing table
Diagnosing DNS Problems
nslookup google.com # DNS resolution
dig google.com # Detailed DNS info
cat /etc/resolv.conf # DNS configuration
Checking Network Interfaces
ip addr show # Interface status
ethtool eth0 # Link status
iwconfig wlan0 # WLAN status
Exercise
In this exercise, we will practically apply the most important concepts from the article.
Exercise tasks:
┌─────────── Fundamentals ────────────────────────────────────┐
│ 1. Check network status │
│ 2. DNS configuration │
│ 3. Firewall rules │
├─────────── Goals ───────────────────────────────────────────┤
│ • Interface configuration │
│ • Set up DNS server │
│ • Set up basic firewall │
└─────────────────────────────────────────────────────────────┘
Task 1: Basic network configuration
# 1. Check your network interfaces
ip addr show
# 2. Configure a static IP
sudo ip addr add 192.168.1.100/24 dev eth0
# 3. Set the default route
sudo ip route add default via 192.168.1.1
Task 2: DNS configuration
# 1. Configure DNS server
sudo nano /etc/resolv.conf
# Add:
nameserver 8.8.8.8
nameserver 8.8.4.4
# 2. Test DNS resolution
nslookup google.com
Task 3: Basic firewall setup
# 1. Enable UFW
sudo ufw enable
# 2. Create basic rules
sudo ufw default deny incoming
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
# 3. Check status
sudo ufw status verbose
Command Reference (Cheatsheet)
For quick access during network administration, troubleshooting, and firewall configuration, the following reference table summarizes the most important Linux commands:
| Command / Syntax | Category | Function & Description |
|---|---|---|
ip link show |
Interfaces | Shows all network adapters and their link status (UP/DOWN). |
ip addr show |
IP Addresses | Lists all IPv4 and IPv6 addresses of all interfaces. |
ip route show |
Routing | Shows kernel routing table and active default gateway. |
ip route get <IP> |
Routing | Determines interface and next-hop for a specific destination IP. |
sudo netplan try |
Netplan | Tests YAML network configuration with automatic 120s rollback. |
sudo netplan apply |
Netplan | Applies Netplan network configurations permanently. |
nmcli device status |
NetworkManager | Shows status and connection profiles of all NetworkManager devices. |
nmcli connection up <id> |
NetworkManager | Activates a defined NetworkManager connection profile. |
resolvectl status |
DNS | Shows active DNS servers and search domains of systemd-resolved. |
dig +short <domain> |
DNS | Provides precise IP addresses of a domain via DNS query. |
sudo ss -tulpn |
Ports & Sockets | Lists all listening TCP/UDP sockets with associated PID. |
sudo ufw default deny incoming |
Firewall | Sets restrictive default policy for all incoming packets. |
sudo ufw allow 22/tcp |
Firewall | Opens TCP port 22 (SSH) in the Uncomplicated Firewall. |
sudo ufw limit 22/tcp |
Firewall | Activates automatic rate limiting against SSH brute-force attacks. |
sudo ufw status verbose |
Firewall | Shows detailed list of all active UFW rules and policies. |
nc -zv <host> <port> |
Diagnose | Checks quick TCP connectivity to a target port (Netcat). |
traceroute <host> |
Diagnose | Shows hop-by-hop router stations on the way to the target. |
Further Resources
The following guides, specifications, and internal course modules deepen Linux network configuration and troubleshooting:
| Resource | Description |
|---|---|
| Netplan Documentation | Official documentation for declarative YAML network configuration. |
| iproute2 Documentation | Official guide for ip, ss, tc, and network namespaces. |
| systemd-resolved Manual | Official documentation for the systemd Name Resolution Service. |
| UFW Community Documentation | Comprehensive guide for the Uncomplicated Firewall on Ubuntu/Debian. |
| Linux Administration #3: Processes | The previous module: processes, signals, nice & cgroups. |
| Linux Administration #5: Shell Scripting | The next module: automation, cron, traps & bash. |
| Command Line Processor in Linux | Fundamental knowledge about shells, I/O streams, and pipes. |
Conclusion
Network management is the fundamental link that integrates standalone Linux servers into fail-safe cloud and data center infrastructures. Through mastery of modern iproute2 commands, declarative network configuration via Netplan and NetworkManager, transparent DNS resolution via systemd-resolved, and solid firewall rules with UFW and nftables, you are able to set up high-availability server networks and systematically locate disruptions during operation.
💡 Practical Tip: Always test new network configurations via Netplan with
sudo netplan try. This command applies the configuration and automatically reverts it after 120 seconds if you lock yourself out of SSH access due to a typo and cannot confirm the timeout with Enter in time.
In the next module of our administration course, we turn to automating recurring tasks: 👉 Next up: Linux Administration #5: Shell Scripting and Automation
👉 Course Overview: All Linux Administration Articles & Modules