Linux Networking Cheat Sheet

Comprehensive Linux networking commands for interfaces, sockets, packet capture, and throughput testing.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Interfaces and Addresses
Show IP addresses
ip addr show

# Display IPv4 and IPv6 addresses on all interfaces.

Show addresses for one interface
ip addr show dev eth0

# Inspect addresses for a specific device.

Add IP address
sudo ip addr add 192.168.1.10/24 dev eth0

# Assign an additional IP address to an interface.

Delete IP address
sudo ip addr del 192.168.1.10/24 dev eth0

# Remove an IP address from an interface.

Show NIC details
sudo ethtool eth0

# Display link speed, duplex, and driver information.

Show NIC statistics
sudo ethtool -S eth0

# Display per-interface statistics exposed by the driver.

Show NetworkManager devices
nmcli device status

# List devices managed by NetworkManager and their states.

Show host IPs
hostname -I

# Print IP addresses assigned to the local host.

## Sockets and Connections
Show listening TCP sockets
ss -ltnp

# List listening TCP sockets with names.

Show listening UDP sockets
ss -lunp

# List listening UDP sockets with names.

Show established connections
ss -tp state established

# Display established TCP sessions.

Filter sockets by port
ss -ltnp '( sport = :443 )'

# Find sockets using a specific local port.

Show process using port
sudo lsof -iTCP:8080 -sTCP:LISTEN -n -P

# Find which process owns a TCP port.

Show open network files
sudo lsof -i -n -P

# List network connections for all processes.

Show PID using port
sudo fuser 5432/tcp

# Identify processes using a TCP port.

Test TCP connectivity
nc -vz example.com 443

# Check whether a remote TCP port is reachable.

Listen on a TCP port
nc -lv 9000

# Open a simple TCP listener for testing.

Forward a local port
socat TCP-LISTEN:8080,fork TCP:127.0.0.1:80

# Create a TCP port forward with socat.

Watch socket changes
watch -n 2 'ss -s; echo; ss -ltnp'

# Refresh socket view every 2 seconds.

## Packet Capture and Throughput
Capture packets on interface
sudo tcpdump -i eth0

# Capture packets on a specific network interface.

Capture one port
sudo tcpdump -i any tcp port 443

# Capture traffic for a single TCP port.

Capture one host
sudo tcpdump -i any host 10.0.0.5

# Capture traffic to or from a host.

Write packets to pcap
sudo tcpdump -i any -w capture.pcap

# Save a capture to a file for Wireshark analysis.

Read packets from pcap
tcpdump -nn -r capture.pcap

# Inspect a saved packet capture file.

Run combined ping and traceroute
mtr example.com

# Continuously test latency and path quality.

Start iperf3 server
iperf3 -s

# Start a throughput test server.

Run iperf3 client
iperf3 -c 10.0.0.10

# Benchmark throughput to a remote host.

Run reverse throughput test
iperf3 -c 10.0.0.10 -R

# Measure reverse-direction throughput.

Flood ping (privileged)
sudo ping -f 10.0.0.10

# Send packets as fast as possible for stress testing.

Recommended next

No recommendations yet.