【FreeBSD】查看端口占用

Posted by 西维蜀黍 on 2021-05-03, Last Modified on 2021-09-21

Find Used Ports

An example of the netstat command with flags:

## Show listening sockets ##
sockstat -l
 
## Show listening sockets for IPv4 only ##
sockstat -4 -l
 
## Show listening sockets for IPv6 only ##
sockstat -6 -l

Find Selected Ports

You can use the grep command to select a certain ports. In this example, find out if port 22 and 80 is open or not:

sockstat -4 -l | grep :22
sockstat -4 -l | grep :80

Reference