OpenBSD List Open TCP or UDP Network Ports

How do I find out open TCP or UDP network ports under OpenBSD operating systems using the command line options?

Tutorial details
DifficultyEasy (rss)
Root privilegesNo/Yes
You need to use the netstat command. This command display network status in various network-related data structures. There are a number of output formats, depending on the options for the information presented. Another option is to use the nmap command from a remote computer, laptop or desktop system running *BSD, macOS, Unix or Linux operating systems. This page shows how to list open UDP or TCP network ports on a OpenBSD operating system.


Syntax: OpenBSD list open TCP or UDP network ports

The syntax is:
netstat [option] netstat -f inet -t
netstat -f inet -u

Let us see see some examples to display a list of open TCP/UDP network ports on OpenBSD.

Task: Display tcp and UDP open port

Type the following command:
$ netstat -nat
$ netstat -na -f inet
$ netstat -na -f inet | grep LISTEN
$ netstat -atn | grep LISTEN
OpenBSD List Open TCP or UDP Network Ports With netstat
Just display IPv4 tcp ports, run:
$ netstat -f inet -at
Sample outputs:

Active Internet connections (including servers)
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
tcp        0      0  openbsd.23087          resolver1.opendn.domai TIME_WAIT
tcp        0      0  openbsd.22            dsl-KK-dynamic-1.32789 ESTABLISHED
tcp        0    448  openbsd.22            dsl-KK-dynamic-1.32786 ESTABLISHED
tcp        0      0  *.22                  *.*                    LISTEN
tcp        0      0  localhost.submissi     *.*                    LISTEN
tcp        0      0  localhost.smtp         *.*                    LISTEN
tcp        0      0  *.time                 *.*                    LISTEN
tcp        0      0  *.daytime              *.*                    LISTEN
tcp        0      0  *.auth                 *.*                    LISTEN
Active Internet connections (including servers)
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
udp        0      0  localhost.biff         *.*
udp        0      0  *.syslog               *.*

fstat command to display info about TCP or UDP and open files on OpenBSD

You can use fstat command to find out more about port 22 or 80 or 443 as follows:
fstat | grep ':80'
fstat | grep ':443'
fstat | grep ':22'

Sample outputs:

root     sshd        7296    3* internet stream tcp 0xd538e334 <--
root     sshd        1358    3* internet6 stream tcp 0xd53a7000 *:22
root     sshd        1358    4* internet stream tcp 0xd53a7198 *:22

Under Unix everything is a file. So you can use the fstat command to get info about open files.

systat command to display system statistics

One can get network connections info using the systat command. The syntax is as follows:
sysstat netstat
sysstat netstat all
sysstat netstat names
sysstat netstat numbers
sysstat netstat tcp
sysstat netstat udp
sysstat netstat other

openbsd systat netstat all output

Click to enlarge image

Each address is displayed in the format "server:port". The options are as follows:

  1. all - Toggle the displaying of server processes awaiting requests.
  2. names -Display network addresses symbolically.
  3. numbers - Display network addresses numerically.
  4. reset - Reset matching mechanisms to the default.
  5. tcp | udp | other - Display only network connections using the indicated protocol.

Other examples

To see information about the network interface:
$ netstat -i
Sample outputs:

Name    Mtu   Network     Address              Ipkts Ierrs    Opkts Oerrs Colls
lo0     33192                                6     0        6     0     0
lo0     33192 loopback    localhost.nixcraf        6     0        6     0     0
lo0     33192 localhost.n localhost.nixcraf        6     0        6     0     0
lo0     33192 fe80::%lo0/ fe80::1%lo0              6     0        6     0     0
pcn0    1500        00:0c:29:7b:66:72      560     0      485     0   124
pcn0    1500 openbsd.nixcraft.      560     0      485     0   124
pcn0    1500  fe80::%pcn0 fe80::20c:29ff:fe      560     0      485     0   124
pflog0* 33192                                0     0        0     0     0
pfsync0 1460                                 0     0        0     0     0
enc0*   1536                                 0     0        0     0     0

To see information about the specified interface called pcn0, run:
$ netstat -I pcn0

A note about /etc/services file

The /etc/services] file is a service name database. It contains information regarding the known services and port numbers. One can view it with the help of grep command, cat command, egrep command, or more command/less command:
$ cat /etc/services
$ grep 80 /etc/services
$ grep -w '443/tcp' /etc/services
$ more /etc/services

OpenBSD etc services file with port numbers

A note about using nmap command

You can use the nmap command to list open ports on a remote server/desktop:
See how to use nmap to find out remote system open port. Read man page of netstat for more information.


You just learned how to display open TCP and UDP network ports on a OpenBSD system using various command line utilties. I suggest that you read the netstat command man page by typing the man command:
$ man 1 netstat

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdig host ip nmap
Package Managerapk apt
Processes Managementbg chroot disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w

1 comment… add one
  • S!FE Sep 27, 2010 @ 23:52

    sockstat -l -P tcp

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.