Network Configuration Basics
Modern Linux distributions use either NetworkManager (desktop systems) or systemd-networkd / Netplan (servers) to manage network connections. Understanding both approaches is essential for any Linux administrator.
Viewing Network Interfaces
ip addr show
# Short version
ip a
# Show only active interfaces
ip link show up
# Show routing table
ip route show
Configuring a Static IP with Netplan (Ubuntu Server)
network:
version: 2
ethernets:
eth0:
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8
# Apply the configuration
sudo netplan apply
NetworkManager CLI (nmcli)
nmcli connection show
# Show active Wi-Fi networks
nmcli device wifi list
# Connect to a Wi-Fi network
nmcli device wifi connect "NetworkName" password "password123"
# Set a static IP
nmcli connection modify "Wired connection 1" \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "1.1.1.1,8.8.8.8" \
ipv4.method manual
nmcli connection up "Wired connection 1"
DNS Configuration
DNS (Domain Name System) translates human-readable domain names into IP addresses. On modern Linux systems, DNS is typically managed through systemd-resolved or configured directly in /etc/resolv.conf.
resolvectl status
# Test DNS resolution
dig linuxland.nl
nslookup linuxland.nl
# Edit hosts file for local overrides
sudo nano /etc/hosts
# 192.168.1.50 myserver.local
Network Troubleshooting Tools
| Tool | Purpose | Example |
|---|---|---|
ping | Test basic connectivity | ping -c 4 google.com |
traceroute | Trace the path packets take | traceroute google.com |
dig | DNS lookup and diagnostics | dig example.com A |
ss | Show open sockets and ports | ss -tulnp |
curl | HTTP requests and testing | curl -I https://example.com |
wget | Download files | wget https://example.com/file.zip |
nmap | Network and port scanning | nmap -sV 192.168.1.1 |
tcpdump | Capture and analyse packets | sudo tcpdump -i eth0 port 80 |
mtr | Combined ping and traceroute | mtr google.com |
Common Troubleshooting Workflow
ip link show
# Step 2: Check if you have an IP address
ip addr show
# Step 3: Test local network (gateway)
ping -c 3 192.168.1.1
# Step 4: Test external connectivity
ping -c 3 1.1.1.1
# Step 5: Test DNS resolution
ping -c 3 google.com
# Step 6: Check open ports and listening services
sudo ss -tulnp
This step-by-step approach isolates the problem layer by layer: interface, IP, local network, internet, then DNS.
Managing Network Services
Checking Open Ports
sudo ss -tulnp
# Find what process is using port 80
sudo ss -tlnp | grep :80
# Scan your own server for open ports
sudo nmap -sT localhost
SSH Tunnelling and Port Forwarding
SSH tunnels let you securely forward traffic through an encrypted connection, which is useful for accessing remote services or bypassing firewalls:
# Forwards local port 8080 to remote port 80
ssh -L 8080:localhost:80 user@remote-server
# Remote port forwarding: expose local service remotely
ssh -R 9090:localhost:3000 user@remote-server
# SOCKS proxy through SSH
ssh -D 1080 user@remote-server
VPN on Linux
Virtual Private Networks encrypt all traffic between your machine and the VPN server. Linux supports several VPN protocols natively.
WireGuard
A modern, fast, and lightweight VPN protocol built into the Linux kernel since version 5.6. WireGuard uses state-of-the-art cryptography and is significantly simpler to configure than older alternatives. It is now the recommended choice for most Linux VPN setups.
OpenVPN
The most widely supported VPN protocol with broad compatibility across platforms and commercial VPN providers. OpenVPN is battle-tested and runs in userspace, making it highly portable. Most commercial VPN services provide OpenVPN configuration files.
WireGuard Quick Setup
sudo apt install wireguard -y
# Generate key pair
wg genkey | tee privatekey | wg pubkey > publickey
# Create configuration
sudo nano /etc/wireguard/wg0.conf
[Interface]
PrivateKey = YOUR_PRIVATE_KEY
Address = 10.0.0.1/24
ListenPort = 51820
[Peer]
PublicKey = PEER_PUBLIC_KEY
AllowedIPs = 10.0.0.2/32
Endpoint = peer.example.com:51820
# Start the VPN interface
sudo wg-quick up wg0
# Enable on boot
sudo systemctl enable wg-quick@wg0
Network Monitoring
sudo apt install iftop -y
sudo iftop -i eth0
# Monitor network connections
sudo apt install nethogs -y
sudo nethogs eth0
# Network statistics per interface
ip -s link show eth0
Learn about managing software on Linux.
Package Management →