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
Difficulty level Easy
Root privileges No/Yes
Requirements netstat/fstat
Est. reading time N/A
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

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 

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

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

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 Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron 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
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
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> for code samples. Still have questions? Post it on our forum