Use net-tools netstat to display listening TCP sockets numerically.
Exclude established connections and UDP sockets.
Which command is appropriate?
netstat -lnt combines listening, numeric, and TCP filters. The modern equivalent for this purpose is commonly ss -lnt.
Detailed explanation
netstat -antIncorrect. It displays all TCP sockets, not only listeners.
Incorrect. It displays all TCP sockets, not only listeners.
netstat -lunIncorrect. It displays listening UDP sockets.
Incorrect. It displays listening UDP sockets.
netstat -lntCorrect. It combines listening, numeric, and TCP filters.
Correct. It combines listening, numeric, and TCP filters.
netstat -rnIncorrect. It displays a routing table numerically.
Incorrect. It displays a routing table numerically.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' '-l=listening' '-n=numeric' '-t=TCP'Expected result
-l=listening
-n=numeric
-t=TCPKey points
- -l means listening
- -t means TCP
- -n means numeric
Notes
- Environment: net-tools netstatのoption対応表
- 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.