Skip to main content

Linux Networking

Essential networking skills for DevOps and system administration. If servers are the buildings in your infrastructure, networking is the road system connecting them. Every deployment, every API call, every SSH session travels over these roads. Understanding them is the difference between debugging a connectivity issue in five minutes versus five hours.

Network Configuration

Viewing Network Interfaces

Testing Connectivity

When something is not working, you troubleshoot layer by layer. Start simple and work up.
Troubleshooting order: ping (is the host reachable?) then port check (is the service listening?) then DNS (is name resolution working?) then traceroute (where does the path break?). This layered approach saves you from chasing the wrong problem.

Viewing Open Ports and Connections


SSH - Secure Shell

SSH is how you access remote servers. It encrypts everything — passwords, commands, file transfers. In production, SSH is your primary interface to every server you manage.

Connecting

SSH Key Authentication

Keys are both more secure and more convenient than passwords. The private key stays on your machine; the public key goes on the server.

SSH Config File

Instead of typing long SSH commands, define shortcuts in ~/.ssh/config:

Copying Files

SSH Tunneling

SSH tunnels let you securely access services on remote networks as if they were local. Think of it as building a secret underground passage between two buildings — traffic flows through the encrypted tunnel, invisible to anyone watching the surface. This is invaluable for reaching databases, admin panels, or internal services that are not exposed to the internet. Instead of opening ports on your firewall (risky), you tunnel through SSH (secure).
Production gotcha: SSH tunnels are fragile — if the SSH connection drops (network blip, idle timeout), the tunnel dies silently and your application gets connection errors. For persistent tunnels, use autossh which automatically reconnects, or configure ServerAliveInterval 60 and ServerAliveCountMax 3 in your SSH config to detect and recover from dead connections.

Firewall Basics

A firewall controls which network traffic is allowed in and out of your server. On a fresh server, the first thing you do (after setting up SSH keys) is configure the firewall.

UFW (Uncomplicated Firewall)

UFW is the beginner-friendly frontend for iptables on Ubuntu/Debian systems.
The number one firewall mistake: Enabling UFW without first allowing SSH. You will be locked out of your server with no way back in except through the cloud provider’s console. Always run sudo ufw allow 22/tcp (or your custom SSH port) before sudo ufw enable.

iptables (Advanced)

iptables is the underlying firewall system. UFW generates iptables rules for you, but knowing iptables helps when you need fine-grained control or are debugging complex networking.

DNS Configuration

Understanding DNS configuration helps when servers cannot resolve hostnames.

Key Takeaways

  • Use ip addr and ip route (not the deprecated ifconfig) for network info
  • Troubleshoot connectivity in layers: ping, port check, DNS, traceroute
  • SSH key authentication is both more secure and more convenient than passwords
  • Use ~/.ssh/config to define connection shortcuts for servers you access frequently
  • SSH tunnels give you secure access to remote services without exposing them publicly
  • Always allow SSH before enabling a firewall — or you will lock yourself out
  • ss -tulpn is the go-to command for “what is listening on which port”

Next: Linux Shell Scripting →