Skip to content

Linux Networking CLI

Many commands below need root privileges to show everything or make changes. Prefix with sudo when you see “permission denied” or incomplete output.

Command What it does
ip addr Show IP addresses on all interfaces
ip -br addr Brief, one-line-per-interface address summary
ip link Show interfaces and their up/down state
sudo ip link set eth0 up Bring an interface up
ip route Show the routing table
ip route get 8.8.8.8 Show which route and source address would be used for a destination
ip neigh Show the ARP/neighbour table
Command What it does
ss -tulpn List TCP and UDP listening sockets with numeric ports and owning process (sudo needed to see all processes)
ss -tn state established Show established TCP connections
ss -tn dst 192.168.1.10 Show connections to a specific address
Command What it does
sudo tcpdump -i eth0 Capture on interface eth0
sudo tcpdump -nn -i eth0 Do not resolve names or port numbers
sudo tcpdump -nn host 192.168.1.10 Only traffic to or from one host
sudo tcpdump -nn port 502 Only traffic on port 502 (for example Modbus/TCP)
sudo tcpdump -nn -i eth0 -w capture.pcap Write packets to a file to open in Wireshark
tcpdump -nn -r capture.pcap Read a saved capture
Command What it does
nmcli device status List network devices and their state
nmcli connection show List saved connections
nmcli device wifi list Scan for Wi-Fi networks
nmcli device wifi connect "SSID" password "secret" Connect to a Wi-Fi network
nmcli connection up "name" Activate a saved connection
Command What it does
sudo ufw status verbose Show firewall state and rules
sudo ufw allow 22/tcp Allow SSH
sudo ufw allow from 192.168.1.0/24 to any port 502 proto tcp Allow a subnet to reach one port
sudo ufw deny 23/tcp Block Telnet
sudo ufw enable Turn the firewall on (allow SSH first on remote machines)
Command What it does
systemctl status ssh Show a service’s state and recent log lines
sudo systemctl restart ssh Restart a service
sudo systemctl enable --now mosquitto Start a service now and at boot
systemctl list-units --type=service List loaded services
Command What it does
journalctl -u ssh Logs for one service
journalctl -u ssh -f Follow logs live
journalctl -b Logs since the current boot
journalctl --since "1 hour ago" Logs from a time window
journalctl -p err Only error priority and worse
Command What it does
docker ps List running containers
docker ps -a List all containers including stopped
docker logs -f NAME Follow a container’s logs
docker exec -it NAME sh Open a shell inside a container
docker compose up -d Start a compose stack in the background
docker compose down Stop and remove the stack