In this article, we will see how to find open ports in FreeBSD using sockstat. 10 useful commands.
Sockstat is a one of the versatile command line utility. It is mainly use for finding open ports in FreeBSD and sockstat command is installed by default in FreeBSD. It’s commonly used for displaying the name of the processes who opened a certain network port on a FreeBSD system.
Sockstat command is also use for listing open sockets based on protocol version(IPv4 and IPv6), on the state of the connection and on what ports a daemon or a program binds and listens on. It can shrink the results for an opened connection based on the user who owns the socket, the file descriptor of a network socket or the PID of the process who opened the socket.
1. Display all open ports in FreeBSD
Sockstat command will display all open ports in a FreeBSD system
# sockstat
2. List of listening ports
# sockstat -l
sockstat command with -l flag will display all listening sockets opened in the networking stack. Show listening sockets.
3. Display IPv4 open ports
# sockstat -4
Show AF_INET (IPv4) sockets.
4. Display IPv6 open ports
# sockstat -6
Show AF_INET6 (IPv6) sockets.
5. Display TCP or UDP open ports
# sockstat -P tcp
# sockstat -P udp
# sockstat -P tcp,udp
Only show Internet sockets if the local or foreign port number is on the specified list. The ports argument is a comma separated list of port numbers and ranges specified as first and last port separated by a dash.
6. List TCP and UDP specific port number
# sockstat -P tcp -p 443 [Show TCP HTTPS Port] # sockstat -P udp -p 53 [Show UDP DNS Port] # sockstat -P tcp -p 443,53,80,21 [Show Both TCP and UDP]
This will check that the mention port is open or not.
7. Display network listening ports
# sockstat -46 -l -s
To list all opened TCP sockets in listening state append the -l and -s flags, as shown in the below example. Being a connectionless protocol, UDP maintains no information about the state of the connection.
8. Display unix sockets and named pipes
# sockstat -u
Show AF_LOCAL (UNIX) sockets. Unix domain sockets, as well as other forms of local inter-process communication, such as named pipes, can be displayed by sockstat command by using the -u flag, as shown in the below image.
9. Dispay HTTPS Connected Protocols
# sockstat -46 -s -P TCP -p 443 -c
You can list all connected sockets associated with HTTPS protocol alongside the state of each connection by running the below command.
10. Display HTTP Remote Sockets
# sockstat -46 -c | egrep ’80|443′ | awk ‘{print $7}’ | uniq -c | sort -nr
# sockstat -46 -c -p 80,443 | grep -v ADDRESS|awk ‘{print $7}’ | uniq -c | sort -nr
To list all remote sockets associated with the HTTP protocol, you can run one of the following command combinations.
In this article, we have seen how to find open port in FreeBSD using sockstat.
[Need assistance to fix this error or install tools? We’ll help you.]