Linux Networking CLI Cheat Sheet
Quick reference guide for Linux Networking: ip, ss, netstat, dig, traceroute, iptables, and ufw.
CLI & Shell
linux
networking
ip
Modern Linux distributions use iproute2 utilities (ip, ss) for network interface management, socket monitoring, routing tables, and firewall rules.
Interface & Routing Management (`ip`)
Table
| Modern Command | Legacy Equivalent | Action / Purpose |
|---|---|---|
ip addr show | ifconfig | Show all network interfaces and assigned IP addresses |
ip addr add 192.168.1.50/24 dev eth0 | ifconfig eth0 ... | Assign static IP address to network interface |
ip link set dev eth0 up/down | ifconfig eth0 up/down | Enable or disable a network interface |
ip route show | route -n | Display Kernel IP routing table |
ip route add default via 192.168.1.1 | route add default ... | Set default gateway IP address |
ip neigh show | arp -n | Display ARP neighbor cache table |
Socket Statistics (`ss`)
bash
# Display listening TCP & UDP sockets with process name and port numbers
ss -tulnp
# Display active ESTABLISHED TCP connections
ss -t -a state established
# Count connection states summary
ss -s
DNS & Route Diagnostics (`dig`, `traceroute`, `ping`)
bash
# Query DNS records (A, AAAA, MX, TXT) with short output
dig +short example.com A
dig example.com MX
# Query specific DNS resolver server (e.g. 8.8.8.8)
dig @8.8.8.8 example.com +trace
# Trace network hop path to destination
traceroute example.com
# Ping destination with specific count and interval
ping -c 4 -i 0.5 1.1.1.1
Firewall Rules (`ufw` & `iptables`)
bash
# UFW (Uncomplicated Firewall)
sudo ufw status verbose
sudo ufw allow 22/tcp
sudo ufw allow 80,443/tcp
sudo ufw enable
# Quick iptables list
sudo iptables -L -n -v
Common Pitfalls & Tips
[!WARNING] Changes made via
ip addr addorip route addare temporary and will be lost on system reboot unless configured in netplan or network interfaces files.
[!TIP] Use
ssinstead of deprecatednetstat;ssreads socket information directly from kernel netlink space and executes much faster on systems with high connection volumes.