How To Check and List Listening Ports with Netstat In Linux


netstat is very useful tool which provides a lot of information about the network of operating system. netstat command can list ip addreass, route, port, connections etc. More detailed information about the netstat command can be found in the following tutorial.

Linux Netstat Command With Examples

List All Listening Ports

We can use netstat -l options in order to list all listening ports. This will list both TCP and UDP ports with IPv4 and IPv6 . But also Unix domain sockets will be printed in the end of the list after TCP and UDP ports.

$ netstat -l
List All Listening Ports
List All Listening Ports

List Listening TCP Ports

TCP is reliable protocol which provides non data loss. Applications generally prefers and uses TCP protocol for network connections and data transfer. We can use -t option in order to only list TCP ports.

$ netstat -l -t
List Listening TCP Ports
List Listening TCP Ports

List Listening UDP Ports

We have also have the ability to only list UDP ports. We will use -u option in order to only list UDP ports.

$ netstat -l -u
List Listening UDP Ports
List Listening UDP Ports

List Established Connections

We can also list only established connections by removing -l option which is used in previous examples. -l was used to list only listening ports.

$ netstat
List Established Connections
List Established Connections

Filter The Port List

Now the most funny part. If we are running netstat in a busy server or system we will get a lot of output. In this situations we should filter printed list. We will use grep command where detailed information can be get from following tutorial.

Introduction to Linux Grep Command With Examples

Filter SSH Port

$ netstat -l | grep ssh

Filter HTTP Port

$ netstat -l | grep http

Filter RDP Port

$ netstat -l | grep rdp

Filter Telnet Port

$ netstat -l | grep telnet

Filter Multiple Ports In Single Command

If we need to filter multiple ports in a single command we should use grep or logic. In this example we will filter both ssh and telnet ports in single command.

$ netstat -l | grep "ssh|telnet"
Filter Multiple Ports In Single Command
Filter Multiple Ports In Single Command

LEARN MORE  Linux fuser Command Tutorial With Examples

2 thoughts on “How To Check and List Listening Ports with Netstat In Linux”

  1. This page explained command to determining if a port is in use on Linux or Unix-like server. For more information see the nmap command and lsof command page online here

    Reply

Leave a Comment