Advance

Find out list of all Open Ports in Linux

Find out list of all Open Ports in Linux
1
(1)

A Linux system administrator needs to know some Linux tricks. In this article, you will learn how to Find out list of all Open Ports in Linux.

In computer networking, and more definitely in software terms, a port is a logical entity that acts as an endpoint of communication to identify a given application or process on a Linux vps operating system. It is a 16-bit number (0 to 65535) which differentiates one application from another on end systems.

The two most popular Internet transport protocols, Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) and other less known protocols use port numbers for communication sessions.

In addition, a combination of an IP address, port, and protocol such as TCP/UDP is known as a socket, and every service must have a unique socket.

 

How to Find out list of all Open Ports in Linux

Join us to talk about ports in computer networking and move to how you can list all open ports in Linux.

Recommended Article: How To Set Up SSH keys On Ubuntu 20.04

 

Let’s have a look at the different categories of ports:

  1. 0-1023 – the Well Known Ports, also referred to as System Ports.
  2. 1024-49151 –the Registered Ports, also known as User Ports.
  3. 49152-65535 –the Dynamic Ports, also referred to as the Private Ports.

 

You can use the following command to view a list of different applications and port/protocol combination in /etc/services file in Linux.

cat /etc/services   OR  cat /etc/services | less
Network Services and Ports
# /etc/services:  # $Id: services,v 1.48 2009/11/11 14:32:31 ovasik Exp $  #  # Network services, Internet style  # IANA services version: last updated 2009-11-10  #  # Note that it is presently the policy of IANA to assign a single well-known  # port number for both TCP and UDP; hence, most entries here have two entries  # even if the protocol doesn't support UDP operations.  # Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports  # are included, only the more common ones.  #  # The latest IANA port assignments can be gotten from  #       http://www.iana.org/assignments/port-numbers  # The Well Known Ports are those from 0 through 1023.  # The Registered Ports are those from 1024 through 49151  # The Dynamic and/or Private Ports are those from 49152 through 65535  #  # Each line describes one service, and is of the form:  #  # service-name  port/protocol  [aliases ...]   [# comment]    tcpmux          1/tcp                           # TCP port service multiplexer  tcpmux          1/udp                           # TCP port service multiplexer  rje             5/tcp                           # Remote Job Entry  rje             5/udp                           # Remote Job Entry  echo            7/tcp  echo            7/udp  discard         9/tcp           sink null  discard         9/udp           sink null  systat          11/tcp          users  systat          11/udp          users  daytime         13/tcp  daytime         13/udp  qotd            17/tcp          quote  qotd            17/udp          quote  msp             18/tcp                          # message send protocol  msp             18/udp                          # message send protocol  chargen         19/tcp          ttytst source  chargen         19/udp          ttytst source  ftp-data        20/tcp  ftp-data        20/udp  # 21 is registered to ftp, but also used by fsp  ftp             21/tcp  ftp             21/udp          fsp fspd  ssh             22/tcp                          # The Secure Shell (SSH) Protocol  ssh             22/udp                          # The Secure Shell (SSH) Protocol  telnet          23/tcp  telnet          23/udp

To list all open ports or currently running ports including TCP and UDP in Linux, You will use netstat, which is a powerful tool for monitoring network connections and statistics.

netstat -lntu    Proto Recv-Q Send-Q Local Address               Foreign Address             State        tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN        tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN        tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN        tcp        0      0 :::22                       :::*                        LISTEN        tcp        0      0 :::80                       :::*                        LISTEN        tcp        0      0 :::25                       :::*                        LISTEN        udp        0      0 0.0.0.0:68                  0.0.0.0:*

Where,

  1. -l – prints only listening sockets
  2. -n – shows the port number
  3. -t – enables listing of tcp ports
  4. -u – enables listing of udp ports

 

 

Please consider that you can also use the ss command, a well known useful utility for examining sockets in a Linux system. Run the command below to list all your open TCP and UCP ports:

List All Network Ports Using ss Command
ss -lntu    Netid State      Recv-Q Send-Q               Local Address:Port       Peer Address:Port   udp   UNCONN     0      0                    *:68                     *:*       tcp   LISTEN     0      128                  :::22                    :::*       tcp   LISTEN     0      128                  *:22                     *:*       tcp   LISTEN     0      50                   *:3306                   *:*       tcp   LISTEN     0      128                  :::80                    ::*       tcp   LISTEN     0      100                  :::25                    :::*       tcp   LISTEN     0      100                  *:25

 

 

Conclusion

In this article, by reaching here you have finished this tutorial and learned how to Find out list of all Open Ports in Linux. For the last point, understanding the concept of ports in computer networking is very vital for system and network administrators. If you need more information about this subject find our related articles on How to Find Out Which Process Listening On A Particular Port AND 5 Interesting Command Line Tips and Tricks in Linux.

How useful was this post?

Click on a star to rate it!

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

View More Posts
Tom Veitch
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

10 thoughts on “Find out list of all Open Ports in Linux

    1. After opening the terminal application, you can use any one of the commands below to check if a port is in use on Linux:
      sudo lsof -i -P -n | grep LISTEN. sudo netstat -tulpn | grep LISTEN. sudo netstat -tulpn | grep :443. sudo ss -tulpn | grep LISTEN. sudo ss -tulpn | grep ':22'

    1. nmap is an open source tool for network exploration and security auditing. We are going to use nmap to find and list open ports in Linux:
      Sudo nmap -sT -O localhost
      sudo nmap -sU -O 192.168.2.254 ##[ list open UDP ports ]##
      sudo nmap -sT -O 127.0.0.1 ##[ list open TCP ports ]##
      sudo nmap -sTU -O 192.168.2.24

    1. You can check all the listening ports and applications on linux if you follow the below path:
      • First, open a terminal application i.e. shell prompt.
      • Run any one of the following command on Linux to see open ports:
      sudo lsof -i -P -n | grep LISTEN
      sudo netstat -tulpn | grep LISTEN
      sudo lsof -i:22 ## see a specific port such as 22 ##
      sudo nmap -sTU -O IP-address-Here

    1. If you are working with windows, type the below commands to check port usage from windows operating system:

      netstat -bano | more
      netstat -bano | grep LISTENING
      netstat -bano | findstr /R /C:"[LISTEING]"

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day