≡ Menu

OpenBSD List Open TCP or UDP Network Ports

How do I find out open tcp or udp network ports under OpenBSD operating systems using command line options?


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 nmap command from a remote computer.

Task: Display tcp and UDP open port

Type the following command:
$ netstat -nat
OR
$ netstat -na -f inet
OR
$ netstat -na -f inet | grep LISTEN
OR
$ netstat -at | grep LISTEN
Sample outputs:

$ netstat -at | grep LISTEN
tcp        0      0  *.291                  *.*                    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
tcp6       0      0  *.ssh                  *.*                    LISTEN
tcp6       0      0  localhost.submissi     *.*                    LISTEN
tcp6       0      0  localhost.smtp         *.*                    LISTEN
tcp6       0      0  *.time                 *.*                    LISTEN
tcp6       0      0  *.daytime              *.*                    LISTEN
tcp6       0      0  *.auth                 *.*                    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

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

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

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  75.126.68.4 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

See how to use nmap to find out remote system open port. Read man page of netstat for more information.

{ 1 comment… add one }
  • S!FE September 27, 2010, 11:52 pm

    sockstat -l -P tcp

Leave a Comment


   Tagged with: , ,