Use netstat to display listening TCP and UDP sockets numerically and show PID and program names where permitted.
Which command is appropriate?
netstat -tulpn lists TCP and UDP listeners, numeric endpoints, and PID/program information. Process details can require additional privileges.
Detailed explanation
netstat -antIncorrect. It shows all TCP sockets and omits UDP, listener filtering, and processes.
Incorrect. It shows all TCP sockets and omits UDP, listener filtering, and processes.
netstat -rnpIncorrect. It displays a numeric routing table.
Incorrect. It displays a numeric routing table.
netstat -tulpnCorrect. It lists TCP/UDP listeners with process and numeric information.
Correct. It lists TCP/UDP listeners with process and numeric information.
netstat -iIncorrect. It displays interface statistics.
Incorrect. It displays interface statistics.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' '-t=TCP' '-u=UDP' '-l=listening' '-p=PID/program' '-n=numeric'Expected result
-t=TCP
-u=UDP
-l=listening
-p=PID/program
-n=numericKey points
- Check listeners across protocols
- -p shows processes
- -n avoids name resolution
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.