Linux Networking Guide

Configure interfaces, routes, DNS, and troubleshoot network issues on Linux.

Category: Linux

What You’ll Learn

  • View and configure network interfaces with ip and nmcli
  • Set static IP addresses and configure DNS resolvers
  • Manage routes and default gateways
  • Troubleshoot connectivity with ping, traceroute, ss, and netstat
  • Configure a firewall with UFW
  • Test DNS resolution with dig and nslookup

View Network Interfaces

Show all interfaces and their IP addresses:

ip addr show
ip link show

Set a Static IP (Ubuntu / Netplan)

Edit the Netplan config (Ubuntu 18.04+):

sudo nano /etc/netplan/00-installer-config.yaml
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses: [192.168.1.10/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]
sudo netplan apply

View and Manage Routes

# Show routing table
ip route show

# Add a static route
sudo ip route add 10.0.0.0/8 via 192.168.1.1

# Delete a route
sudo ip route del 10.0.0.0/8

DNS Configuration

Edit /etc/resolv.conf or configure via systemd-resolved:

# Check current DNS
resolvectl status

# Test DNS resolution
dig google.com
nslookup google.com 8.8.8.8

Troubleshooting Commands

# Test connectivity
ping -c 4 8.8.8.8

# Trace the route to a host
traceroute google.com

# Check open ports and connections
ss -tulpn
netstat -tulpn

# Check if a port is reachable
nc -zv 192.168.1.10 22

# Capture packets on an interface
sudo tcpdump -i eth0 port 80

Restart Networking

# Restart NetworkManager
sudo systemctl restart NetworkManager

# Restart systemd-networkd
sudo systemctl restart systemd-networkd