/errors/ss/ss-command-not-found
bash: ss: command not found
- tool
- ss / netstat
- exit code
- 127
- versions
- iproute2
- os
- linux, macos
bash: ss: command not found means the shell found no ss program in any directory of PATH. ss (socket statistics) is part of the Linux iproute2 package, which minimal container images often leave out, and it does not exist on macOS. Install the package (apt-get install iproute2 on Debian/Ubuntu, dnf install iproute on Fedora/RHEL, apk add iproute2 on Alpine), or use lsof or netstat on macOS.
Reproduce it
Simulate a system without ss by running it with an empty PATH:
(PATH=/nonexistent; ss -tlnp)
echo "exit code: $?"Output
bash: line 1: ss: command not found exit code: 127
Exit code 127 is the shell's code for "command not found"; ss itself never ran.
Install it
| System | Command | Package |
|---|---|---|
| Debian, Ubuntu | apt-get update && apt-get install -y iproute2 | iproute2 |
| Fedora, RHEL, Rocky, Alma | dnf install -y iproute | iproute |
| Alpine | apk add iproute2 | iproute2 |
| Arch | pacman -S iproute2 | iproute2 |
| openSUSE | zypper install iproute2 | iproute2 |
Run these as root (or with sudo). In a Dockerfile, add the package to the image instead of installing it into a running container, which loses it on the next restart.
Without installing anything
- In a container, run
ssfrom the host in the container's network namespace:nsenter -t PID -n ss -tlnp, wherePIDis the container's main process on the host (docker inspect -f '{{.State.Pid}}' NAME). - Read the kernel tables directly:
cat /proc/net/tcp /proc/net/tcp6(ports are in hexadecimal). - On macOS:
lsof -nP -iTCP -sTCP:LISTENlists listening TCP sockets with their processes;netstat -an -p tcplists all TCP sockets.
Found as root but not as a user
On some distributions ss lives in /usr/sbin or /sbin, which is in root's PATH but not always in a normal user's or a cron job's. Check with ls -l /usr/sbin/ss /sbin/ss; if it is there, call it by full path or add the directory to PATH.