• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Sunday, June 8, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
202
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Requirements
  2. 1. List All Opened Ports in FreeBSD
  3. 2. List Listening or Opened Ports in FreeBSD
  4. 3. List IPv4 Opened Ports in FreeBSD
  5. 4. List IPv6 Opened Ports in FreeBSD
  6. 5. List TCP or UDP Opened Ports in FreeBSD
    1. Show only TCP sockets
    2. Show only UDP sockets
  7. 6. List TCP and UDP Specific Port Numbers
  8. 7. List Opened and Connected Ports in FreeBSD
  9. 8. List Network Listening Ports in FreeBSD
  10. 9. List Unix Sockets and Named Pipes
  11. 10. List Ports Opened by Application in FreeBSD
  12. 11. List HTTPS Connected Protocols
  13. 12. List HTTP Remote Sockets
  14. 13. Find Highest HTTP Requests By IP Addresses
  15. 14. List DNS Opened Sockets
  16. 15. Query TCP DNS on Local Domain

Sockstat is a versatile command line utility used for displaying network and system opened sockets in FreeBSD. Mainly, sockstat command is installed by default in FreeBSD and it’s commonly used for displaying the name of the processes who opened a certain network port on a FreeBSD system.

However, sockstat can also list open sockets based on protocol version (both IP versions), on the state of the connection and on what ports a daemon or a program binds and listens on.

Read Also: 20 Useful ‘netstat’ Command Examples to Check Network Connections

It can also display inter-process communication sockets, typically known as Unix domain sockets or IPC. Sockstat command combined with grep filter or piped through awk utility proves to be a powerful tool for the local networking stack.

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.

In this guide we’ll list some common utilization examples, but also very powerful, of sockstat command line networking utility in FreeBSD.

Requirements

  1. FreeBSD 11.1 Installation Guide

1. List All Opened Ports in FreeBSD

Simply executed without any options or switches, sockstat command will display all opened sockets in a FreeBSD system, as illustrated in the below screenshot.

# sockstat
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

Display Network Ports in FreeBSD

The values displayed in the sockstat output are described as:

  • USER : The owner (user account) of the socket.
  • COMMAND : The command which with opened the socket.
  • PID : The process ID of the command which owns the socket.
  • FD : The file descriptor number of the socket.
  • PROTO : The transport protocol (usually TCP/UDP) associated with the opened socket or socket type in case of unix domain sockets (datagram, stream or seqpac) for UNIX sockets.
  • LOCAL ADDRESS : It represents the local IP address for IP based sockets. In case of Unix sockets it represents endpoint filename attached to the socket. The “??” notation implies that the socket endpoint could not be recognized or established.
  • FOREIGN ADDRESS : The remote IP address where the socket is connected to.

2. List Listening or Opened Ports in FreeBSD

Executed with the -l flag, sockstat command will display all listening sockets opened in the networking stack and all opened unix domain sockets or named pipes involved in some kind of local data processing in the system.

# sockstat -l
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List Opened Network Ports

3. List IPv4 Opened Ports in FreeBSD

To display all opened sockets for IPv4 protocol only, issue the command with the -4 flag, as suggested in the below example.

# sockstat -4
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List IPv4 Opened Ports in FreeBSD

4. List IPv6 Opened Ports in FreeBSD

Similar to IPv4 version, you can also display the opened network sockets for IPv6 only, by issuing the command as shown below.

# sockstat -6
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List IPv6 Opened Ports

5. List TCP or UDP Opened Ports in FreeBSD

In order to display network sockets based only on a specified network protocol, such as TCP or UDP, use the -P flag, followed by the argument name of the protocol.

The protocol names can be found by inspecting the content of the /etc/protocols file. Currently, the ICMP protocol is not supported by the sockstat tool.

Show only TCP sockets
# sockstat -P tcp
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List TCP Opened Ports

Show only UDP sockets
# sockstat -P udp
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List UDP Opened Ports

Chain both protocols.

# sockstat –P tcp,udp

6. List TCP and UDP Specific Port Numbers

If you want to display all TCP or UDP IP opened sockets, based on the local or remote port number, use the below command flags and syntax, as illustrated in the below screenshot.

# 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]
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List Specific TCP Port

7. List Opened and Connected Ports in FreeBSD

In order to display all opened and connected sockets, use the -c flag. As shown in the below samples, you can list all HTTPS connected sockets or all TCP connected sockets by issuing the commands.

# sockstat -P tcp -p 443 -c
# sockstat -P tcp -c
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List Opened and Connected Ports

8. List Network Listening Ports in FreeBSD

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.

UDP opened sockets cannot be displayed by using their state, because the udp protocol uses datagrams to send/receive data and has no build-in mechanism to determine the state of the connection.

# sockstat -46 -l -s
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List Network Listening Ports

9. List Unix Sockets and Named Pipes

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.

# sockstat -u
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List Unix Sockets

10. List Ports Opened by Application in FreeBSD

Sockstat command output can be filtered through grep utility in order to display a list of ports opened by a specific application or command.

Suppose you want to list all sockets associated with Nginx web server, you can issue the following command to achieve the task.

# sockstat -46 | grep nginx
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List Application Listening Sockets

To display only the connected sockets associated with Nginx web server, issue the following command.

# sockstat -46 -c| grep nginx

11. List HTTPS Connected Protocols

You can list all connected sockets associated with HTTPS protocol alongside the state of each connection by running the below command.

# sockstat -46 -s -P TCP -p 443 -c
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List HTTPS Connected Protocols

12. List HTTP Remote Sockets

To list all remote sockets associated with the HTTP protocol, you can run one of the following command combinations.

# 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
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List Remote HTTP Protocols

13. Find Highest HTTP Requests By IP Addresses

In case you want to find how many HTTP connections are requested by each remote IP address, issue the below command. This command can be very useful in case you want to determine if your web server is under some kind of DDOS attack. In case of suspicions, you should investigate the IP addresses with the highest request rate.

# sockstat -46 -c | egrep '80|443' | awk '{print $7}' | cut -d: -f1 | uniq -c | sort –nr

14. List DNS Opened Sockets

If you have configured a caching and forward DNS server at your premises to serve internal clients via TCP transport protocol and you want to display a list of all sockets
opened by the resolver, along with the state of each socket connection, execute the following command.

# sockstat -46 -P tcp –p 53 -s
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

List DNS Opened Sockets

15. Query TCP DNS on Local Domain

If there’s no DNS traffic on the network, you can manually trigger a DNS query on the TCP socket from the local machine’s console by running the following dig command. Afterwards, issue the above command to list all resolver sockets.

# dig +tcp  www.domain.com  @127.0.0.1
15 Useful ‘Sockstat Command Examples’ to Find Open Ports in FreeBSD

Query TCP DNS on Local

That’s all! Along with netstat and lsof command line utilities, sockstat command line is a powerful utility used for acquiring network information and troubleshoot multiple aspects of FreeBSD networking stack and networking related processes and services.

The FreeBSD sockstat command counterpart in Linux is represented by the netstat or the newly ss command. Believe it or not, based on sockstat utility, you can find a similar application developed for Android OS, named SockStat – Simple Netstat GUI.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

Wikit – A Command Line Tool to Search Wikipedia in Linux

Next Post

4 Useful Tools to Run Commands on Multiple Linux Servers

Next Post

4 Useful Tools to Run Commands on Multiple Linux Servers

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In