🛰️
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
| Command | What it does |
|---|---|
ip -br addr | Brief list of interfaces and their IP addresses. |
ip addr show eth0 | Show one interface in detail. |
ip link | List interfaces and their link state. |
ip route | Show the routing table. |
ip route get 8.8.8.8 | Show which route and source address would be used to reach a host. |
ip neigh | Show the ARP/neighbour table. |
sudo ip link set eth0 up | Bring an interface up (down to disable). |
sudo ip addr add 192.168.1.10/24 dev eth0 | Add an address temporarily (lost at reboot). |
Ports and connections
| Command | What it does |
|---|---|
ss -tulpn | Listening TCP/UDP ports with the owning process (needs sudo for process names). |
ss -tn state established | Established TCP connections. |
ss -s | Connection summary statistics. |
sudo lsof -i :8080 | Which process is using port 8080. |
nc -zv host 22 | Test whether a TCP port is open. |
nc -zv host 20-25 | Test a range of ports. |
Reachability
| Command | What it does |
|---|---|
ping -c 4 host | Send four ICMP echo requests. |
traceroute host | Show the hops to a host (or tracepath if traceroute is missing). |
mtr host | Combined ping and traceroute, live. |
curl -I https://host | Check that a web server responds. |
curl -s ifconfig.me | Show your public IP address. |
DNS
| Command | What it does |
|---|---|
dig example.com | Query DNS with full details. |
dig +short example.com | Just the answer. |
dig example.com MX | Query a specific record type. |
dig @8.8.8.8 example.com | Ask a specific DNS server. |
dig -x 203.0.113.5 | Reverse DNS lookup. |
dig +trace example.com | Follow the delegation from the root servers. |
resolvectl status | Show DNS settings on systemd-resolved systems. |
host example.com | Quick forward lookup. |
Capture and hardware
| Command | What it does |
|---|---|
sudo tcpdump -i eth0 port 80 | Capture traffic on one port. |
sudo tcpdump -nn -i any host 203.0.113.5 | Capture traffic to or from a host, no name resolution. |
sudo tcpdump -i eth0 -w capture.pcap | Save a capture for Wireshark. |
sudo ethtool eth0 | Show link speed and duplex. |
hostnamectl | Show 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.