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

Inspect links, IP addresses, MTU, and interface state.

Show IP addresses

Display IPv4 and IPv6 addresses on all interfaces.

bashLINUXipaddressinterfaces
bash
ip addr show

Display IPv4 and IPv6 addresses on all interfaces.

Show addresses for one interface

Inspect addresses for a specific device.

bashLINUXipaddressinterface
bash
ip addr show dev eth0

Inspect addresses for a specific device.

Add IP address

Assign an additional IP address to an interface.

bashLINUXipaddressconfigure
bash
sudo ip addr add 192.168.1.10/24 dev eth0

Assign an additional IP address to an interface.

Delete IP address

Remove an IP address from an interface.

bashLINUXipaddressconfigure
bash
sudo ip addr del 192.168.1.10/24 dev eth0

Remove an IP address from an interface.

Show NIC details

Display link speed, duplex, and driver information.

bashLINUXethtoolniclink
bash
sudo ethtool eth0

Display link speed, duplex, and driver information.

Show NIC statistics

Display per-interface statistics exposed by the driver.

bashLINUXethtoolstatsnic
bash
sudo ethtool -S eth0

Display per-interface statistics exposed by the driver.

Show NetworkManager devices

List devices managed by NetworkManager and their states.

bashLINUXnmclinetworkmanagerinterfaces
bash
nmcli device status

List devices managed by NetworkManager and their states.

Show host IPs

Print IP addresses assigned to the local host.

bashLINUXhostnameipquick-reference
bash
hostname -I

Print IP addresses assigned to the local host.

Sockets and Connections

Inspect listening ports, established sessions, and owning processes.

Show listening TCP sockets

List listening TCP sockets with names.

bashLINUXsstcpports
bash
ss -ltnp

List listening TCP sockets with names.

Show listening UDP sockets

List listening UDP sockets with names.

bashLINUXssudpports
bash
ss -lunp

List listening UDP sockets with names.

Show established connections

Display established TCP sessions.

bashLINUXsstcpconnections
bash
ss -tp state established

Display established TCP sessions.

Filter sockets by port

Find sockets using a specific local port.

bashLINUXssportfilter
bash
ss -ltnp '( sport = :443 )'

Find sockets using a specific local port.

Show process using port

Find which process owns a TCP port.

bashLINUXlsofportsprocess
bash
sudo lsof -iTCP:8080 -sTCP:LISTEN -n -P

Find which process owns a TCP port.

Show open network files

List network connections for all processes.

bashLINUXlsofnetworkinspect
bash
sudo lsof -i -n -P

List network connections for all processes.

Show PID using port

Identify processes using a TCP port.

bashLINUXfuserportprocess
bash
sudo fuser 5432/tcp

Identify processes using a TCP port.

Test TCP connectivity

Check whether a remote TCP port is reachable.

bashLINUXnctcpconnectivity
bash
nc -vz example.com 443

Check whether a remote TCP port is reachable.

Listen on a TCP port

Open a simple TCP listener for testing.

bashLINUXnclistenertest
bash
nc -lv 9000

Open a simple TCP listener for testing.

Forward a local port

Create a TCP port forward with socat.

bashLINUXsocatport-forwardtest
bash
socat TCP-LISTEN:8080,fork TCP:127.0.0.1:80

Create a TCP port forward with socat.

Watch socket changes

Refresh socket view every 2 seconds.

bashLINUXwatchssmonitoring
bash
watch -n 2 'ss -s; echo; ss -ltnp'

Refresh socket view every 2 seconds.

Packet Capture and Throughput

Capture packets and benchmark throughput.

Capture packets on interface

Capture packets on a specific network interface.

bashLINUXtcpdumpcaptureinterface
bash
sudo tcpdump -i eth0

Capture packets on a specific network interface.

Capture one port

Capture traffic for a single TCP port.

bashLINUXtcpdumpportcapture
bash
sudo tcpdump -i any tcp port 443

Capture traffic for a single TCP port.

Capture one host

Capture traffic to or from a host.

bashLINUXtcpdumphostcapture
bash
sudo tcpdump -i any host 10.0.0.5

Capture traffic to or from a host.

Write packets to pcap

Save a capture to a file for Wireshark analysis.

bashLINUXtcpdumppcapcapture
bash
sudo tcpdump -i any -w capture.pcap

Save a capture to a file for Wireshark analysis.

Read packets from pcap

Inspect a saved packet capture file.

bashLINUXtcpdumppcapread
bash
tcpdump -nn -r capture.pcap

Inspect a saved packet capture file.

Run combined ping and traceroute

Continuously test latency and path quality.

bashLINUXmtrlatencypath
bash
mtr example.com

Continuously test latency and path quality.

Start iperf3 server

Start a throughput test server.

bashLINUXiperf3throughputserver
bash
iperf3 -s

Start a throughput test server.

Run iperf3 client

Benchmark throughput to a remote host.

bashLINUXiperf3throughputclient
bash
iperf3 -c 10.0.0.10

Benchmark throughput to a remote host.

Run reverse throughput test

Measure reverse-direction throughput.

bashLINUXiperf3throughputreverse
bash
iperf3 -c 10.0.0.10 -R

Measure reverse-direction throughput.

Flood ping (privileged)

Send packets as fast as possible for stress testing.

bashLINUXpingstressicmp
bash
sudo ping -f 10.0.0.10

Use with care on controlled networks only.

Recommended next

No recommendations yet.