Troubleshooting Network Connectivity Issues in Linux: Complete Guide

By Tech Writer Linux
Learn how to diagnose and fix network problems in Linux. Covers ping, traceroute, DNS issues, firewall problems, and interface configuration.

Common Network Problems in Linux

Network connectivity issues can be frustrating, but with the right diagnostic tools, most problems can be quickly identified and resolved.

Quick Network Diagnostics

Check Network Interface Status

# View all interfaces
ip addr show
# or older command
ifconfig

# Check if interface is up
ip link show

Test Basic Connectivity

# Ping gateway
ping -c 4 192.168.1.1

# Ping external server
ping -c 4 8.8.8.8

# Ping by hostname (tests DNS)
ping -c 4 google.com

Check Routing

# View routing table
ip route show
# or
route -n

# Trace route to destination
traceroute google.com
traceroute -n 8.8.8.8  # Skip DNS lookups

Common Issues and Solutions

Problem 1: No Network Connection

Symptoms: Interface shows DOWN, no connectivity

Solutions:

# Bring interface up
sudo ip link set eth0 up
# or
sudo ifconfig eth0 up

# Restart NetworkManager
sudo systemctl restart NetworkManager

# Restart networking service
sudo systemctl restart networking

Problem 2: DHCP Not Working

Symptoms: No IP address assigned

Solutions:

# Release and renew DHCP
sudo dhclient -r  # Release
sudo dhclient     # Renew

# Or with dhcpcd
sudo dhcpcd -k eth0  # Release
sudo dhcpcd eth0     # Renew

# Check DHCP status
sudo systemctl status dhcpcd

Problem 3: DNS Resolution Failing

Symptoms: Can ping IPs but not hostnames

Solutions:

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

# Check DNS servers
cat /etc/resolv.conf

# Temporarily use Google DNS
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

# For permanent change (Ubuntu/Debian with systemd-resolved)
sudo nano /etc/systemd/resolved.conf
# Add: DNS=8.8.8.8 1.1.1.1
sudo systemctl restart systemd-resolved

Problem 4: Firewall Blocking Connections

Check firewall status:

# UFW (Ubuntu)
sudo ufw status verbose

# firewalld (CentOS/RHEL)
sudo firewall-cmd --list-all

# iptables
sudo iptables -L -n -v

Temporary testing:

# Disable UFW temporarily
sudo ufw disable

# Stop firewalld temporarily
sudo systemctl stop firewalld

# Clear iptables (CAREFUL!)
sudo iptables -F

Problem 5: Wrong Network Configuration

Configure static IP (netplan - Ubuntu 18.04+):

sudo nano /etc/netplan/01-netcfg.yaml

Add:

network:
  version: 2
  ethernets:
    eth0:
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]

Apply:

sudo netplan apply

Advanced Troubleshooting Tools

Network Traffic Analysis

# Capture packets
sudo tcpdump -i eth0
sudo tcpdump -i eth0 port 80

# Monitor bandwidth
sudo iftop
sudo nethogs

# Check listening ports
sudo netstat -tulpn
sudo ss -tulpn

Check for Network Hardware Issues

# Check kernel messages
dmesg | grep -i network
dmesg | grep -i eth

# View interface statistics
ip -s link show eth0

# Check driver info
ethtool eth0

WiFi-Specific Issues

List WiFi Networks

# Scan for networks
sudo iwlist wlan0 scan | grep ESSID

# Or with newer tools
nmcli device wifi list

Connect to WiFi

# Using nmcli
nmcli device wifi connect SSID password password

# Or with wpa_supplicant
sudo wpa_passphrase SSID password | sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf

Network Performance Issues

Test Connection Speed

# Install speedtest-cli
sudo apt install speedtest-cli
speedtest-cli

# Or use iperf for LAN testing
# On server:
iperf -s
# On client:
iperf -c server_ip

Check for Packet Loss

# Continuous ping with statistics
ping -c 100 8.8.8.8 | tail -3

# MTR (better than traceroute)
mtr google.com

Common Configuration Files

  • /etc/network/interfaces - Network configuration (Debian/older Ubuntu)
  • /etc/netplan/*.yaml - Network configuration (Ubuntu 18.04+)
  • /etc/resolv.conf - DNS servers
  • /etc/hosts - Static hostname mappings
  • /etc/NetworkManager/ - NetworkManager configuration

Systematic Troubleshooting Approach

  1. Check if interface is up: ip link show
  2. Check if you have an IP: ip addr show
  3. Ping gateway: ping 192.168.1.1
  4. Ping external IP: ping 8.8.8.8
  5. Test DNS: ping google.com
  6. Check routing: ip route show
  7. Check firewall: sudo ufw status
  8. Review logs: journalctl -u NetworkManager

Prevention and Best Practices

  • Keep network drivers updated
  • Document your network configuration
  • Use static IPs for servers
  • Monitor network performance regularly
  • Keep backups of working configurations
  • Test changes in non-production first

Conclusion

Most network issues in Linux can be resolved by following a systematic approach: verify physical connectivity, check interface status, test connectivity at each network layer, and examine configuration files. The tools covered in this guide will help you diagnose and fix the vast majority of network problems.