>_cat linux-networking-tools.md|Network & Security
Linux Networking Tools Cheatsheet
SPEC: MDX·/linux-networking-tools·Firewalls, VPNs, routing, certificates, DNS, and tunneling.
A comprehensive reference for modern Linux network administration and troubleshooting. Replaces legacy utilities (ifconfig, netstat, route) with modern standards: iproute2, ss, nmcli, ethtool, tcpdump, dig, nmap, and iperf3.
Interface & IP Address Management (ip)
The ip utility from iproute2 is the modern standard for managing network links and IP assignments.
# Interface & IP address inspection
ip a # Show all interfaces and IP addresses
ip -br a # Brief summary showing UP/DOWN state and IPs
ip link show # Layer-2 link status (MAC address, state, MTU)
ip -s link show eth0 # Packet statistics (RX/TX packets, bytes, errors, drops)
# Link control
sudo ip link set eth0 up
sudo ip link set eth0 down
sudo ip link set eth0 mtu 9000 # Configure Jumbo Frames MTU
# Manual IP assignment (Runtime)
sudo ip addr add 192.168.1.50/24 dev eth0 # Add static IP
sudo ip addr add 192.168.1.51/24 dev eth0 label eth0:1 # Add secondary alias IP
sudo ip addr del 192.168.1.50/24 dev eth0 # Remove IP address
sudo ip addr flush dev eth0 # Flush all IP configurations on an interfaceRouting Tables & Gateways (ip route)
# Display routing table
ip route show # List active routing rules
ip route get 8.8.8.8 # Determine interface and gateway used to reach a destination IP
# Default gateway & static routing
sudo ip route add default via 192.168.1.1 dev eth0 # Set default gateway
sudo ip route del default # Remove default gateway
sudo ip route add 10.0.0.0/8 via 192.168.1.254 dev eth0 # Add static route to subnet
sudo ip route del 10.0.0.0/8 # Remove static routeNetworkManager CLI (nmcli)
Standard utility on enterprise Linux (RHEL, Rocky, AlmaLinux, CentOS, Fedora) and Ubuntu.
# Devices & connections overview
nmcli device status # Summary of physical network devices
nmcli connection show # List all saved connection profiles
nmcli connection show --active # List currently active connection profiles
# Connection control
sudo nmcli connection up "eth0" # Activate a connection profile
sudo nmcli connection down "eth0" # Deactivate a connection profile
sudo nmcli connection reload # Reload connection files from disk
# Static IP configuration via nmcli
sudo nmcli connection modify "eth0" ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "1.1.1.1 8.8.8.8"
sudo nmcli connection up "eth0" # Apply changes
# Wi-Fi network management
nmcli device wifi list # Scan available Wi-Fi SSIDs
sudo nmcli device wifi connect "SSID_NAME" password "WIFI_PASSWORD"Hardware Link Status & Driver Diagnostics (ethtool)
# Check physical link speed, duplex, and cable status
sudo ethtool eth0
# Key parameters to verify:
# Speed: 1000Mb/s or 10000Mb/s (10Gbps)
# Duplex: Full
# Link detected: yes (physical link established)
# Hardware error & drop counters (NIC ring buffer)
sudo ethtool -S eth0 | grep -iE "drop|error"
# Identify physical port in server chassis (Blinks interface LED)
sudo ethtool -p eth0 10 # Blink port LED for 10 seconds
# Offload capabilities (Hardware acceleration)
sudo ethtool -k eth0 # Check TSO, GSO, and checksum offload statusSocket Statistics & Port Listening (ss)
The ss utility reads socket information directly from kernel space, making it significantly faster and more accurate than legacy netstat.
# Inspecting open listening ports
ss -tuln # Display numeric TCP & UDP listening ports
sudo ss -tulpn # Include process names and Process IDs (PIDs)
sudo ss -tulpn | grep :3306 # Check if database port 3306 is open
# Filter by TCP connection state
ss -wat # Display all active TCP sockets
ss -t state established # Only established connections
ss -t state time-wait # Sockets in TIME-WAIT state
ss -s # Summary of active socket memory usage
# Filter by port or remote address
ss -nt '( dst :80 or dst :443 )' # Outbound connections to web ports
ss -nt 'sport = :22' # Inbound SSH connectionsIdentifying Process Holding a Port (lsof & fuser)
Useful when encountering Address already in use errors during service startup.
# Using lsof
sudo lsof -i :80 # Identify process listening on port 80
sudo lsof -i -P -n | grep LISTEN # List all processes with listening network sockets
# Using fuser
sudo fuser 80/tcp # Display PID of process holding port 80/tcp
sudo fuser -vn tcp 80 # Verbose process details (user, PID, command)
sudo fuser -k 80/tcp # Kill process locking port 80DNS Diagnostics (dig, nslookup, host)
# Query DNS records with dig
dig example.com # Standard A record lookup
dig +short example.com # Output IP address only
dig @1.1.1.1 example.com # Query specific resolver (Cloudflare 1.1.1.1)
# Specific record types
dig -t MX example.com # Mail Exchange record
dig -t TXT example.com # SPF / DKIM verification records
dig -t CNAME cdn.example.com # Canonical Name record
dig -t NS example.com # Authoritative nameservers
# Reverse DNS lookup (IP to domain)
dig -x 1.1.1.1 +short
# Systemd DNS resolver status
resolvectl status # Show active upstream DNS resolvers (systemd-resolved)
cat /etc/resolv.conf # System nameserver configurationConnectivity, Latency & Path Routing
# ICMP ping tests
ping -c 4 1.1.1.1 # Send exactly 4 ping requests
ping -c 5 -s 1472 example.com # Test Path MTU (1472 bytes + 28 byte header = 1500 MTU)
# Hop-by-hop route tracing
traceroute -n example.com # Trace network route without reverse DNS delays
traceroute -T -p 443 example.com # Trace using TCP SYN port 443 (bypasses ICMP blocks)
# Interactive real-time diagnostic (MTR - Ping + Traceroute)
mtr -rw -c 50 example.com # Static 50-packet report measuring per-hop loss and jitter
mtr 1.1.1.1 # Real-time dynamic visual trace
# ARP table management
ip neighbor # Inspect local ARP cache (IP to MAC mapping)
sudo ip neigh flush all # Flush local ARP tablePacket Capturing & Traffic Analysis (tcpdump)
# Basic packet capture
sudo tcpdump -i eth0 # Capture all packets on eth0
sudo tcpdump -i eth0 -n # Disable reverse DNS lookups for faster output
# Port and protocol filtering
sudo tcpdump -i eth0 port 80 # Capture HTTP traffic on port 80
sudo tcpdump -i eth0 port 443 or port 80 # Capture web traffic on port 80 or 443
sudo tcpdump -i eth0 icmp # Capture ICMP ping packets
# Host filtering and boolean logic
sudo tcpdump -i eth0 host 192.168.1.50 # Traffic to or from specific host
sudo tcpdump -i eth0 src 192.168.1.50 # Filter traffic originating from host
sudo tcpdump -i eth0 not port 22 # Exclude SSH traffic to keep console clean
# Inspect packet payload (ASCII view)
sudo tcpdump -A -i eth0 port 80 # ASCII output (useful for raw HTTP inspection)
sudo tcpdump -X -i eth0 port 80 # Output HEX and ASCII side-by-side
# Capture to PCAP file (Wireshark compatible)
sudo tcpdump -i eth0 -w /tmp/capture.pcap -c 1000 # Save first 1,000 packets
tcpdump -r /tmp/capture.pcap # Read captured PCAP fileNetwork Scanning & Exploration (nmap)
# Host discovery (Ping Sweep)
nmap -sn 192.168.1.0/24 # Scan active subnet hosts without port scanning
# Standard port scanning
nmap 192.168.1.10 # Scan 1,000 most common ports
nmap -p 22,80,443,3306 192.168.1.10 # Scan specific ports
nmap -p 1-65535 192.168.1.10 # Scan entire port range (1 to 65535)
# Service version detection
nmap -sV 192.168.1.10 # Identify service versions (OpenSSH, Nginx, etc.)
nmap -sC -sV 192.168.1.10 # Run default NSE scripts and version detection
# Stealth TCP SYN scan (Requires root privileges)
sudo nmap -sS -Pn 192.168.1.10 # SYN scan without initial ping discovery (-Pn)Port Testing & Throughput Benchmarking (nc & iperf3)
Netcat (nc)
# Port reachability check
nc -zv 192.168.1.1 80 # Test TCP port connectivity
nc -zvw 2 192.168.1.1 443 # Test with 2-second timeout
nc -zvu 192.168.1.1 53 # Test UDP port (e.g. DNS)
# Temporary port listener (Firewall verification)
nc -l -p 8080 # Listen on port 8080 for incoming connections
# Banner grabbing
echo "HEAD / HTTP/1.0\r\n\r\n" | nc example.com 80Throughput Benchmarking (iperf3)
Measure raw network throughput between two hosts without disk I/O bottlenecks.
# On receiving server (Host A):
iperf3 -s
# On sending client (Host B):
iperf3 -c 192.168.1.10 # Run 10-second throughput test
iperf3 -c 192.168.1.10 -P 4 # 4 parallel streams to saturate high-speed links
iperf3 -c 192.168.1.10 -R # Reverse mode: measure server download speedReal-Time Bandwidth Monitoring
# Interactive per-connection bandwidth viewer
sudo apt install -y iftop
sudo iftop -i eth0 -n # Monitor live bandwidth by host pair
# Visual throughput graphs (Inbound / Outbound)
sudo apt install -y nload
nload eth0
# Historical bandwidth accounting (Daily / Monthly transfer totals)
sudo apt install -y vnstat
vnstat -i eth0 -h # Hourly transfer stats
vnstat -i eth0 -d # Daily transfer stats
vnstat -i eth0 -m # Monthly transfer statsKernel Network Parameter Tuning (sysctl)
# Enable IP packet forwarding (Required for Routers, VPNs, and Docker hosts)
sudo sysctl -w net.ipv4.ip_forward=1
# Increase TCP connection backlog (Prevents dropped connections during traffic spikes)
sudo sysctl -w net.core.somaxconn=65535
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=8192
# Expand ephemeral port range for outbound connections
sudo sysctl -w net.ipv4.ip_local_port_range="10240 65535"
# Persist in /etc/sysctl.d/99-networking.conf:
# net.ipv4.ip_forward = 1
# net.core.somaxconn = 65535
# net.ipv4.tcp_max_syn_backlog = 8192
# net.ipv4.ip_local_port_range = 10240 65535
# Apply configuration without rebooting:
sudo sysctl -p /etc/sysctl.d/99-networking.conf