Linux Network Administration Cheat Sheet

Your guide to essential networking commands and remote monitoring tools on Linux

Introduction

Managing networks and monitoring remote systems are critical tasks for any Linux system administrator. This cheat sheet covers essential commands and tools to help you efficiently handle networking and remote monitoring on Linux.

Basic Networking Commands

ifconfig            # Display or configure network interfaces
ip addr show        # Show IP addresses
ip link show        # Show link layer information
ip route show       # Display the routing table
ping host           # Send ICMP ECHO_REQUEST to network hosts
traceroute host     # Print the route packets take to the network host
netstat -tuln       # List all listening ports
ss -tuln            # List all listening ports using the socket statistics command
arp -a              # Display the ARP table
hostname            # Show or set the system's hostname

Use Cases

ifconfig: Used to check network interface configurations and troubleshoot network connectivity issues.

ping: Used to check the connectivity between the local system and a remote host.

traceroute: Useful for diagnosing network routing issues by showing the path packets take to reach a host.

netstat and ss: Useful for monitoring network connections and identifying open ports on the system.

Network Configuration

nmtui               # Text user interface for network management
nmcli dev status    # Show device status
nmcli con show      # Show available connections
nmcli con up id "name" # Bring up the specified connection
nmcli con down id "name" # Bring down the specified connection
systemctl restart NetworkManager # Restart the NetworkManager service
/etc/network/interfaces # Network configuration file (Debian/Ubuntu)
cat /etc/resolv.conf # Show DNS servers
resolvectl status   # Show resolver information

Use Cases

nmtui: A user-friendly interface for managing network connections, ideal for users who prefer a graphical interface over command-line.

nmcli: Command-line tool for managing network connections, useful for scripting and automation.

systemctl restart NetworkManager: Useful for applying new network configurations or troubleshooting network issues by restarting the NetworkManager service.

Network Diagnostics

ping -c 4 host      # Ping host with 4 packets
traceroute host     # Trace the path to a host
mtr host            # Network diagnostic tool combining ping and traceroute
dig domain          # DNS lookup
nslookup domain     # Query Internet name servers interactively
whois domain        # Get whois information for a domain
ethtool eth0        # Display or change Ethernet device settings
tcpdump -i eth0     # Dump traffic on interface eth0

Use Cases

mtr: Provides real-time network diagnostic information, useful for identifying network bottlenecks and packet loss.

dig and nslookup: Useful for DNS troubleshooting by querying DNS records for a domain.

ethtool: Provides detailed information about network interfaces and allows for configuration changes, such as enabling/disabling autonegotiation or changing speed settings.

tcpdump: Captures network packets for analysis, useful for troubleshooting complex network issues and security monitoring.

Firewall Management

ufw status          # Check the status of UFW (Uncomplicated Firewall)
ufw enable          # Enable UFW
ufw disable         # Disable UFW
ufw allow port      # Allow traffic on the specified port
ufw deny port       # Deny traffic on the specified port
iptables -L         # List current iptables rules
iptables -A INPUT -p tcp --dport 22 -j ACCEPT # Allow SSH connections
iptables -A INPUT -j DROP # Drop all other incoming traffic

Use Cases

ufw: Simplifies firewall management, making it easier to allow or deny traffic on specific ports without complex rules.

iptables: Provides detailed control over the firewall rules and network traffic filtering, useful for advanced network security configurations.

Remote Access and Monitoring

ssh user@remote_host        # Connect to a remote host via SSH
scp file user@remote_host:/path # Copy file to remote host via SCP
rsync -avz file user@remote_host:/path # Sync files with a remote host via rsync
ssh-keygen                 # Generate SSH keys
ssh-copy-id user@remote_host # Copy SSH key to remote host
tmux                       # Terminal multiplexer for managing multiple sessions
screen                     # Screen manager with VT100/ANSI terminal emulation
top                        # Display dynamic real-time information about running processes
htop                       # Interactive process viewer
nload                      # Monitor network traffic and bandwidth usage
iftop                      # Display bandwidth usage on an interface by host
vnstat                     # Network traffic monitor

Use Cases

ssh: Provides secure remote login capabilities, essential for managing remote servers.

scp and rsync: Useful for securely transferring files between local and remote systems, with rsync providing advanced synchronization options.

tmux and screen: Allows for managing multiple terminal sessions, useful for long-running processes and remote work.

htop: An interactive process viewer that provides an easy-to-read and user-friendly interface for monitoring system resources.

nload and iftop: Real-time network traffic monitoring tools, useful for analyzing bandwidth usage and identifying traffic patterns.

Network Services Management

systemctl start service    # Start a network service
systemctl stop service     # Stop a network service
systemctl restart service  # Restart a network service
systemctl status service   # Check the status of a network service
journalctl -u service      # View logs for a specific service
chkconfig --list           # List all available services (Red Hat-based)
update-rc.d service defaults # Set defaults for a service (Debian-based)

Use Cases

systemctl: Manages systemd services, allowing administrators to start, stop, restart, and check the status of services, which is essential for managing network services like web servers, databases, and firewalls.

journalctl: Provides access to system logs, which is useful for troubleshooting service-related issues.

Miscellaneous Networking Tools

wget URL                   # Download files from the web
curl URL                   # Transfer data from or to a server
ftp host                   # FTP client
sftp user@remote_host      # Secure FTP client
nmap host                  # Network exploration tool and security/port scanner
wireshark                  # Network protocol analyzer

Conclusion

Mastering these commands and tools will greatly enhance your capability to manage and troubleshoot network issues on Linux systems. Keep this cheat sheet handy for quick reference, and practice regularly to become proficient in network administration.