Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No/Yes |
Requirements | netstat/fstat |
Time | N/A |
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
OR
$ netstat -na -f inet
OR
$ netstat -na -f inet | grep LISTEN
OR
$ 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 192.168.1.115:22Under 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:
Each address is displayed in the format "server:port". The options are as follows:
sysstat netstat
sysstat netstat all
sysstat netstat names
sysstat netstat numbers
sysstat netstat tcp
sysstat netstat udp
sysstat netstat other
- all - Toggle the displaying of server processes awaiting requests.
- names -Display network addresses symbolically.
- numbers - Display network addresses numerically.
- reset - Reset matching mechanisms to the default.
- 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 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 0To 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:
nmap 192.168.1.1
See how to use nmap to find out remote system open port. Read man page of netstat for more information.Conclusion
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 ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
sockstat -l -P tcp