Linux Network Commands: Essential Guide for System Administrators

Network troubleshooting and monitoring are critical skills for any Linux system administrator. This comprehensive guide will walk you through the essential Linux networking commands that every sysadmin should know, building upon our previous guides on Linux networking basics.

Table of Contents

Understanding Network Status Commands

Before diving into complex network troubleshooting, you need to understand how to check your system’s network status.

ip Command

The ip command is the modern replacement for the older ifconfig command. Here are the most useful options:

# Show all network interfaces
ip addr show

# Display routing table
ip route show

# Show network interface statistics
ip -s link
Code language: PHP (php)

The ip command provides detailed information about your network interfaces, including IP addresses, MAC addresses, and interface states.

ss Command

The ss command is the successor to netstat and provides information about network connections:

# Show all TCP connections
ss -t

# Display listening ports
ss -lt

# Show all UDP connections
ss -u
Code language: PHP (php)

Network Connectivity Testing

Testing network connectivity is crucial for diagnosing network issues.

ping Command

The ping command is your first line of defense in network troubleshooting:

# Basic ping test
ping -c 4 google.com

# Continuous ping with timestamp
ping -D google.com
Code language: CSS (css)

The -c flag limits the number of ping attempts, while -D adds timestamps to the output.

traceroute Command

Traceroute helps you understand the path your network traffic takes:

# Basic traceroute
traceroute google.com

# Use TCP instead of UDP
traceroute -T google.com
Code language: CSS (css)

DNS Troubleshooting

DNS issues are common network problems. These commands will help you diagnose them.

dig Command

# Basic DNS query
dig google.com

# Query specific DNS server
dig @8.8.8.8 google.com

# Reverse DNS lookup
dig -x 8.8.8.8
Code language: PHP (php)

nslookup Command

# Basic DNS lookup
nslookup google.com

# Query specific record type
nslookup -type=mx google.com
Code language: PHP (php)

Network Interface Configuration

Managing network interfaces is a crucial skill for system administrators.

nmcli Command

NetworkManager’s command-line interface provides powerful network configuration capabilities:

# Show all connections
nmcli connection show

# Show active connections
nmcli connection show --active

# Connect to a WiFi network
nmcli device wifi connect SSID_Name password wireless_password
Code language: PHP (php)

Network Monitoring

Continuous network monitoring helps identify issues before they become critical.

iftop Command

# Monitor bandwidth usage
iftop -i eth0

# Display port numbers
iftop -P
Code language: PHP (php)

nethogs Command

# Monitor per-process bandwidth usage
nethogs eth0
Code language: PHP (php)

Advanced Network Analysis

tcpdump Command

Capture and analyze network traffic:

# Capture traffic on specific interface
tcpdump -i eth0

# Capture specific protocol
tcpdump -i eth0 tcp

# Write capture to file
tcpdump -i eth0 -w capture.pcap
Code language: PHP (php)

Network Security Commands

netstat Command

Despite being older, netstat still provides valuable security information:

# Show listening ports and processes
netstat -tulpn

# Display all active connections
netstat -ant
Code language: PHP (php)

Best Practices

  1. Regular Monitoring: Set up regular monitoring of network interfaces and connections.

  2. Documentation: Keep detailed records of network configurations and changes.

  3. Security: Regularly check for unauthorized network connections and open ports.

  4. Backup Configurations: Always backup network configurations before making changes.

  5. Update Knowledge: Stay current with new networking tools and commands.

Troubleshooting Common Issues

No Internet Connection:

    # Check DNS
    ping 8.8.8.8
    dig google.com
    
    # Check default gateway
    ip route show
    Code language: CSS (css)

    High Latency:

      # Monitor network latency
      ping -c 100 google.com | grep 'time='
      
      # Check network saturation
      iftop
      Code language: PHP (php)

      DNS Resolution Problems:

        # Check DNS servers
        cat /etc/resolv.conf
        
        # Test DNS resolution
        dig +trace google.com
        Code language: PHP (php)

        System Integration

        These network commands integrate well with other Linux system administration tools. For example, you can combine them with Linux process monitoring to get a complete picture of your system’s performance.

        Conclusion

        Mastering these Linux network commands is essential for effective system administration. Start with the basics like ip and ping, then gradually incorporate more advanced tools like tcpdump and nethogs into your workflow. Regular practice and experimentation will help you become proficient in network troubleshooting and monitoring.

        Remember to always verify commands in a test environment before using them in production, and keep security in mind when working with network tools. As you continue your journey in Linux system administration, these commands will become invaluable tools in your arsenal.

        Leave a Comment

        This site uses Akismet to reduce spam. Learn how your comment data is processed.

        Share via
        Copy link
        Powered by Social Snap