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 CommandLegacy EquivalentAction / Purpose
ip addr showifconfigShow all network interfaces and assigned IP addresses
ip addr add 192.168.1.50/24 dev eth0ifconfig eth0 ...Assign static IP address to network interface
ip link set dev eth0 up/downifconfig eth0 up/downEnable or disable a network interface
ip route showroute -nDisplay Kernel IP routing table
ip route add default via 192.168.1.1route add default ...Set default gateway IP address
ip neigh showarp -nDisplay 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 add or ip route add are temporary and will be lost on system reboot unless configured in netplan or network interfaces files.

[!TIP] Use ss instead of deprecated netstat; ss reads socket information directly from kernel netlink space and executes much faster on systems with high connection volumes.