Skip to content

Linux Networking Commands

Linux provides powerful tools for monitoring, diagnosing, and troubleshooting network issues. Below, we explore essential commands and how to use them effectively.

Checking Connectivity

  • Usage: Test connectivity to a host.
    ping google.com
    
  • Sends ICMP packets to the destination and measures the response time.
  • Use Ctrl+C to stop the command.

  • Troubleshooting Example:

    • If ping fails, it could indicate:
    • Network connectivity issues.
    • DNS resolution problems.
  • Usage: Trace the path packets take to a destination.
    traceroute google.com
    
  • Identifies where delays or failures occur in the route.

  • Troubleshooting Example:

    • Use traceroute to pinpoint where packets are getting dropped.

Viewing Network Configuration

  • Usage: Display network interfaces and IP addresses.
    ip addr
    
  • Look for inet to find assigned IPs.

  • Troubleshooting Example:

    • If no IP is assigned, check your DHCP configuration or static IP settings.
  • Usage: Similar to ip addr but older.
    ifconfig
    

Examining Network Connections

  • Usage: Display network connections, routing tables, and more.
    netstat -an
    
  • Usage: Faster, modern replacement for netstat.
    ss -tuln
    
    -Troubleshooting Example:
    • Use ss to identify open ports and active connections.

Querying DNS

  • Usage: Query DNS for IP addresses.
    nslookup google.com
    
  • Usage: Advanced DNS query tool.
    dig google.com
    
  • Troubleshooting Example:
    • Use nslookup or dig to verify DNS resolution.
    • If DNS fails, check your /etc/resolv.conf file or DNS server configuration.