How to check open ports in Linux

When troubleshooting network problems or trying to improve security for Linux computers, you need to know which ports are open. This article will show you some ways to test open ports in Linux.

What is the port (port)?

A port is a 16-bit number (0-65.535) to help identify a certain application or process on the Linux operating system (Unix). Each application has a different port on the Linux system.

Here are the different types of ports:

  1. 0 - 1023 - Called popular port (Well Known Port)
  2. 1024 - 49151 - Called the Registered Port
  3. 49152 - 65535 - Called dynamic port (Dynamic Port)

Use the following command to display the list of applications and ports on Terminal:

 cat / etc / services 

How to check open ports in Linux Picture 1

TCP : TCP stands for Transmission Control Protocol. This is the most commonly used protocol on the Internet. TCP not only communicates one-way, but instead sends back packets to confirm that it receives your packets.

UDP : stands for User Datagram Protocol. It is an alternative communication protocol for TCP. UDP protocol works similar to TCP. However, it ignores all error checking tools. UDP is needed when speeding up without regard to error correction.

SOCKET : Socket allows communication from two different processes on the same machine or on different machines.

  1. How to protect high-risk network ports?

Consider different ways to list an open port in Linux.

1. Netstat command

In this method, we will use the -atu netstat command to test open ports in Linux.

How to check open ports in Linux Picture 2

Here we use the -a, -t and -u flags for netstat.

  1. -a : show all sockets
  2. -t : show TCP connection
  3. -u : display UDP connection

You can also add the -p flag to display the PID of the program name or related process.

How to check open ports in Linux Picture 3

To display only UDP ports, you can use the following command:

 netstat -vaun 

How to check open ports in Linux Picture 4

Alternatively, you can use the following command to search TCP ports:

 netstat -vatn 

How to check open ports in Linux Picture 5

2. lsof command

Instead of using netstat, we can use the lsof command to display open ports in Linux:

 lsof -i 

How to check open ports in Linux Picture 6

The following command can also display open sockets:

 lsof -n -P | grep LISTEN 

How to check open ports in Linux Picture 7

Alternatively, you can use the following command to list all TCP connections:

 lsof -i tcp 

How to check open ports in Linux Picture 8

You can use the following command for UDP connections:

 lsof -i udp 

3. Network mapping command

In this method, we will use nmap to detect open ports on Linux systems. Use the following command to display TCP port connections:

 nmap -sT -O localhost 

How to check open ports in Linux Picture 9

Finally, to display UDP port connections, we can use the following command:

 nmap -sU localhost 

How to check open ports in Linux Picture 10

When it comes to the security of Linux computers, the first thing to do is to close all unnecessary ports to prevent external access. With the methods listed above, you will be able to easily check open ports on your Linux system and determine which ports will close or open.

I wish you all success!

See more:

  1. Guide to network operation for Linux users: 11 commands to know
  2. 5 tools to test Linux networks
  3. Check Linux network traffic with vnStat
5 ★ | 1 Vote

May be interested

  • How to check the time of shutdown and reboot in LinuxHow to check the time of shutdown and reboot in Linux
    there are many reasons why you might want to find out when your linux computer is off, reboot or how long it will run. in most cases, this information is invaluable in debugging a problem.
  • Check the current user on LinuxCheck the current user on Linux
    in linux, you can perform simple tasks such as checking the current user in many ways. this tutorial will show you how to use some of the quickest and easiest ways to check users on linux.
  • How to check the desktop environment you are using on LinuxHow to check the desktop environment you are using on Linux
    as you probably know, linux-based operating systems are heavily focused on the command line to perform operations. a minimal distro like arch linux will give you a dark terminal installation.
  • How to Disable USB PortsHow to Disable USB Ports
    this wikihow teaches you how to turn off your pc's usb ports. usb ports, while useful, can also pose a security risk when left available on a shared computer. you can disable your usb ports using both device manager and the registry editor...
  • How to use Antiword on LinuxHow to use Antiword on Linux
    to open word document files, linux users can use libreoffice. however, not all linux computers can open such heavy graphics applications. in this case, the alternative solution is to use antiword to open document files. the article below tipsmake will guide you how to use antiword on linux.
  • How to find open and blocked TCP / UDP portsHow to find open and blocked TCP / UDP ports
    most likely you are reading this article because an application you are trying to run indicates a port is blocked or you have read the documentation that leaving certain ports open on the network could cause security issues.
  • 4 reputable Linux hardware manufacturers for open source enthusiasts4 reputable Linux hardware manufacturers for open source enthusiasts
    now, more and more computers that come with linux come pre-installed, which you can find. they are suitable for a wide range of users and different financial capabilities.
  • How to install Linux operating system on MacHow to install Linux operating system on Mac
    if you have a mac and want to explore a new open source operating system, check out the instructions on how to install linux on a mac below.
  • How to check the pressure of a Linux systemHow to check the pressure of a Linux system
    testing pressure on linux servers is a good idea if you want to see if they work well. in this post, tipsmake introduces some tools that can help you add pressure to the system to test and evaluate results.
  • How to check and manage disk space in LinuxHow to check and manage disk space in Linux
    a common problem is that updates fail due to a lack of disk space, but there are some simple tests that users can perform when they encounter an error message, to keep critical systems smooth operation.