Tools › Cheat sheets › Networking & Security › Linux networking
🛰️

Linux networking cheat sheet

Modern replacements for ifconfig and netstat, plus the DNS and connectivity tools used to debug a network problem. Some commands need sudo.

Click any command to copy it.

Interfaces and routes

CommandWhat it does
ip -br addrBrief list of interfaces and their IP addresses.
ip addr show eth0Show one interface in detail.
ip linkList interfaces and their link state.
ip routeShow the routing table.
ip route get 8.8.8.8Show which route and source address would be used to reach a host.
ip neighShow the ARP/neighbour table.
sudo ip link set eth0 upBring an interface up (down to disable).
sudo ip addr add 192.168.1.10/24 dev eth0Add an address temporarily (lost at reboot).

Ports and connections

CommandWhat it does
ss -tulpnListening TCP/UDP ports with the owning process (needs sudo for process names).
ss -tn state establishedEstablished TCP connections.
ss -sConnection summary statistics.
sudo lsof -i :8080Which process is using port 8080.
nc -zv host 22Test whether a TCP port is open.
nc -zv host 20-25Test a range of ports.

Reachability

CommandWhat it does
ping -c 4 hostSend four ICMP echo requests.
traceroute hostShow the hops to a host (or tracepath if traceroute is missing).
mtr hostCombined ping and traceroute, live.
curl -I https://hostCheck that a web server responds.
curl -s ifconfig.meShow your public IP address.

DNS

CommandWhat it does
dig example.comQuery DNS with full details.
dig +short example.comJust the answer.
dig example.com MXQuery a specific record type.
dig @8.8.8.8 example.comAsk a specific DNS server.
dig -x 203.0.113.5Reverse DNS lookup.
dig +trace example.comFollow the delegation from the root servers.
resolvectl statusShow DNS settings on systemd-resolved systems.
host example.comQuick forward lookup.

Capture and hardware

CommandWhat it does
sudo tcpdump -i eth0 port 80Capture traffic on one port.
sudo tcpdump -nn -i any host 203.0.113.5Capture traffic to or from a host, no name resolution.
sudo tcpdump -i eth0 -w capture.pcapSave a capture for Wireshark.
sudo ethtool eth0Show link speed and duplex.
hostnamectlShow the hostname and OS information.

Frequently asked questions

What replaced ifconfig and netstat?

ip replaces ifconfig and route, and ss replaces netstat. The old tools are deprecated and often not installed.

How do I see which process uses a port?

Run sudo ss -tulpn | grep :PORT or sudo lsof -i :PORT.

More Networking & Security cheat sheets

🔑 SSH🌐 curl🛡️ ufw🔐 OpenSSL🔒 Certbot (Let's Encrypt)🌐 Subnet / CIDR🧱 iptablesAll Networking & Security cheat sheets →
Copied to clipboard