List only TCP sockets in LISTEN state on the current host.
Do not resolve service names or host names.
Which command is appropriate?
ss -lnt selects listening TCP sockets and numeric addresses and ports. Add -p when process information is needed and permissions allow it.
Detailed explanation
ss -uanIncorrect. -u selects UDP and does not restrict to listening TCP.
Incorrect. -u selects UDP and does not restrict to listening TCP.
ss -lntCorrect. It lists numeric listening TCP sockets.
Correct. It lists numeric listening TCP sockets.
ss -rIncorrect. -r concerns name resolution and does not supply the required filters.
Incorrect. -r concerns name resolution and does not supply the required filters.
ss -xIncorrect. -x selects UNIX-domain sockets.
Incorrect. -x selects UNIX-domain sockets.
Try it yourself
An example you can run in a temporary verification environment.
ss -lnt 2>/dev/null | sed -n '1,5p' || printf '%s
' 'ss is not installed'Expected result
State、Local Address:Portなどの待受TCP一覧、または未導入メッセージKey points
- -l means listening
- -n means numeric
- -t means TCP
Notes
- Environment: iproute2 ss / 読み取り専用
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.