Troubleshooting Linux Networking

Networking issues in Linux can be complex and frustrating, but with the right tools and approach, most problems can be resolved quickly. This guide covers common networking issues and provides step-by-step troubleshooting methods to help you get your Linux system back online.

Common Networking Issues

Network Interface Not Detected

Symptoms:

  • The network interface is missing or not recognized by the system.
  • Commands like ifconfig or ip a do not list the expected network interface.

Troubleshooting Steps:

  • Check Hardware: Ensure the network cable is connected and the network card is properly seated.
  • List Network Interfaces: Use the following command to check if the network interface is detected by the system:
    sudo lshw -C network
  • Reboot and Check dmesg Logs: Reboot the system and check dmesg logs for any hardware detection errors:
    dmesg | grep -i eth
  • Install/Update Drivers: Install or update the network drivers. On Debian/Ubuntu:
    sudo apt-get install firmware-linux-nonfree
    sudo modprobe <network_module>

IP Address Not Assigned

Symptoms:

  • The network interface is detected, but no IP address is assigned.
  • Unable to connect to the network or access the internet.

Troubleshooting Steps:

  • Check DHCP Configuration: Ensure your system is configured to obtain an IP address via DHCP:
    sudo dhclient <interface_name>
  • Static IP Configuration: If using a static IP, verify the settings in /etc/network/interfaces (Debian/Ubuntu) or /etc/sysconfig/network-scripts/ifcfg-<interface> (RHEL/CentOS).
  • Restart Network Services: Restart networking services to apply the configuration:
    sudo systemctl restart networking

DNS Issues

Symptoms:

  • Unable to resolve domain names, but can connect to IP addresses directly.

Troubleshooting Steps:

  • Check DNS Configuration: Verify the DNS servers listed in /etc/resolv.conf:
    cat /etc/resolv.conf
  • Test DNS Resolution: Use dig or nslookup to test DNS resolution:
    dig google.com
    nslookup google.com
  • Flush DNS Cache: Clear the DNS cache if using a caching service like systemd-resolved:
    sudo systemctl restart systemd-resolved

Routing Issues

Symptoms:

  • Unable to reach certain networks or the internet, despite having an IP address.
  • Misconfigured or missing routes.

Troubleshooting Steps:

  • Check Routing Table: Display the current routing table with:
    ip route
  • Add or Modify Routes: If routes are missing, add them manually:
    sudo ip route add default via <gateway_ip>
  • Restart Network Services: After making changes, restart the networking service.

Firewall Blocking Traffic

Symptoms:

  • Network connections fail despite correct configurations.
  • Specific ports or services are unreachable.

Troubleshooting Steps:

  • Check Firewall Rules: Review the active firewall rules with iptables or nftables:
    sudo iptables -L
    sudo nft list ruleset
  • Allow Necessary Ports: Add rules to allow traffic on required ports:
    sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  • Disable Firewall Temporarily: To rule out firewall issues, disable it temporarily:
    sudo systemctl stop firewalld

Go deeper with basic IPTables or advanced IPTables.

Network Performance Issues

Symptoms:

  • Slow network speeds or intermittent connectivity.
  • High latency or packet loss.

Troubleshooting Steps:

  • Test Network Speed: Use iperf or speedtest-cli to measure network performance.
  • Check for Packet Loss: Use ping to check for packet loss:
    ping -c 10 google.com
  • Inspect Network Interfaces: Check for errors on network interfaces:
    ifconfig <interface_name>
  • Adjust MTU Settings: If packet fragmentation is an issue, adjust the MTU size:
    sudo ip link set dev <interface_name> mtu 1400

Best Practices for Network Troubleshooting

Use Logging

Always check logs (/var/log/syslog, dmesg) for clues.

Keep Backups

Backup configuration files before making changes.

Isolate the Issue

Try to determine if the issue is local, network-wide, or related to external services.