Welcome everyone to follow the public account [Xiaobai Technology Circle] and send
B02
orb02
to receive a gift package of Linux learning materials!
1. Use netstat
Instruction
netstat
is a command used to display network status information. To see if a specific port is occupied, you can use the following command:
netstat -tuln | grep 端口号
-t
: Display TCP connection information-u
: Display UDP connection information-l
: Only show ports in listening status-n
: Use numeric format to display the port number instead of the service namegrep 端口号
: Use thegrep
command to filter out the specified port number information
For example, to check whether port number 80 is occupied, you can execute:
netstat -tuln | grep 80
2. Use ss
Instruction
ss
is a more modern tool for displaying socket statistics. It is faster and more efficient than netstat
. To check the port usage, you can use the following command:
ss -tuln | grep 端口号
-t
: Display TCP connection information-u
: Display UDP connection information-l
: Only show ports in listening status-n
: Use numeric format to display the port number instead of the service namegrep 端口号
: Use thegrep
command to filter out the specified port number information
For example, to check whether port number 80 is occupied, you can execute:
ss -tuln | grep 80
3. View all port occupancy status
If you want to view the occupancy of all ports on the system, just omit the grep
command:
Use netstat
:
netstat -tuln
Used by someone ss
:
ss -tuln
This will show all TCP and UDP ports listening.
at last
Now you have learned how to check the port usage on your Linux system! This is useful for diagnosing network problems and understanding system status.