{"id":671,"date":"2024-09-08T16:06:10","date_gmt":"2024-09-08T16:06:10","guid":{"rendered":"https:\/\/webhostingpune.co.in\/blog\/?p=671"},"modified":"2024-09-08T16:06:13","modified_gmt":"2024-09-08T16:06:13","slug":"how-to-check-open-ports-in-linux","status":"publish","type":"post","link":"https:\/\/webhostingpune.co.in\/blog\/how-to-check-open-ports-in-linux\/","title":{"rendered":"How to Check Open Ports in Linux"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Network ports are standardized number identifiers that allow devices to use one IP address to handle multiple network requests simultaneously. Since there are 65535 port numbers, keeping a record of which ports are in use can be challenging.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Linux distribution installed on a computer.<\/li>\n\n\n\n<li>Administrative access to the command line.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#prerequisites\">Prerequisites<\/a><\/li><li><a href=\"#what-is-a-listening-port\">What Is a Listening Port?<\/a><\/li><li><a href=\"#how-to-check-open-ports-in-linux\">How to Check Open Ports in Linux?<\/a><\/li><li><a href=\"#check-ports-via-lsof-command\">Check Ports via lsof Command<\/a><\/li><li><a href=\"#check-ports-via-netstat-command\">Check Ports via netstat Command<\/a><\/li><li><a href=\"#check-ports-via-ss-command\">Check Ports via ss Command<\/a><\/li><li><a href=\"#check-ports-via-nmap-command\">Check Ports via nmap Command<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-a-listening-port\">What Is a Listening Port?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Applications and services use listening ports to listen for incoming network requests. Each listening port is tied to an IP address and a communication protocol such as TCP or UDP.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Depending on the network setup, listening ports can be&nbsp;<strong>open&nbsp;<\/strong>or&nbsp;<strong>closed<\/strong>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Open ports<\/strong>\u00a0accept outside connections using the correct protocol.<\/li>\n\n\n\n<li><strong>Closed ports<\/strong>\u00a0do not accept all the connections. They communicate with a predetermined outside service or application while a firewall blocks other attempted connections.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">One listening port tied can host only one service. For instance, if there is a <a href=\"https:\/\/www.squarebrothers.in\/hosting\/vps-hosting\" target=\"_blank\" rel=\"noopener\">VPS server<\/a> on the system that already uses port 80, any other installed <a href=\"https:\/\/www.webhostingpune.co.in\/web-hosting\/\">hosting server<\/a> will have to use a different, non-default port number.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-check-open-ports-in-linux\">How to Check Open Ports in Linux?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Linux users can check open ports using multiple available networking tools. Each tool displays the same results, but the output format and the amount of information vary.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following sections provide instructions for checking open ports using&nbsp;<strong>lsof<\/strong>,&nbsp;<strong>netstat<\/strong>,&nbsp;<strong>ss<\/strong>,&nbsp;<strong>Nmap<\/strong>, and&nbsp;<strong>netcat&nbsp;<\/strong>utilities.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are few ways to check Open Ports in Linux below is the most and widely used steps and commands,<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"check-ports-via-lsof-command\">Check Ports via lsof Command<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The lsof command allows users to list the programs that utilize listening ports and daemons that maintain active network connections.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the&nbsp;<strong><code>lsof<\/code><\/strong>&nbsp;command to:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Display a list of ports in use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo lsof -nP -iTCP -sTCP:LISTEN<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The command outputs a list of the connections that use the TCP protocol.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"196\" src=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2024\/09\/sshport.png\" alt=\"\" class=\"wp-image-672\" srcset=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2024\/09\/sshport.png 766w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2024\/09\/sshport-300x77.png 300w\" sizes=\"auto, (max-width: 766px) 100vw, 766px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Check a specific port number with this syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo lsof -nP -i:&#91;port-number]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For example, to check if port 32121 is in use, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo lsof -nP -i:32121<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the port is free, the command shows no output. If an application is using the port, the output shows its details:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"881\" height=\"113\" src=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2024\/09\/32121.png\" alt=\"\" class=\"wp-image-673\" srcset=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2024\/09\/32121.png 881w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2024\/09\/32121-300x38.png 300w\" sizes=\"auto, (max-width: 881px) 100vw, 881px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Specify the protocol you wish to scan by adding it to the&nbsp;<strong><code>-i<\/code><\/strong>&nbsp;option.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, to check if the UDP port 83 is open, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo lsof -nP -iUDP:83<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"check-ports-via-netstat-command\">Check Ports via netstat Command<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The netstat command provides a network activity overview and statistics. Use the command below to display the listening ports on the system with\u00a0<strong><code>netstat<\/code><\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo netstat -tunpl<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The command uses five command arguments:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>-t<\/code><\/strong>\u00a0\u2013 Queries the command for TCP ports.<\/li>\n\n\n\n<li><strong><code>-u<\/code><\/strong>\u00a0\u2013 Queries for UDP ports.<\/li>\n\n\n\n<li><strong><code>-n<\/code><\/strong>\u00a0\u2013 Avoids DNS lookup and shows only IP addresses to speed up the process.<\/li>\n\n\n\n<li><strong><code>-p<\/code><\/strong>\u00a0\u2013 Displays the process ID and the name of the program using the port.<\/li>\n\n\n\n<li><strong><code>-l<\/code><\/strong>\u00a0\u2013 Outputs listening ports.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Identify the listening ports\/sockets by checking the&nbsp;<strong><code>State<\/code><\/strong>&nbsp;column and looking for the label&nbsp;<strong><code>LISTENING<\/code><\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"888\" height=\"242\" src=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2024\/09\/tunpl.png\" alt=\"\" class=\"wp-image-674\" srcset=\"https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2024\/09\/tunpl.png 888w, https:\/\/webhostingpune.co.in\/blog\/wp-content\/uploads\/2024\/09\/tunpl-300x82.png 300w\" sizes=\"auto, (max-width: 888px) 100vw, 888px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"check-ports-via-ss-command\">Check Ports via ss Command<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The ss command is a faster and easier-to-use version of the obsolete&nbsp;<strong><code>netstat<\/code><\/strong>&nbsp;command. It uses the same options as&nbsp;<strong><code>netstat<\/code><\/strong>, but provides more statistics in the output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following command scans TCP and UDP ports for listening sockets and displays them in a list:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ss -tunl<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The listening ports\/sockets are marked as\u00a0<strong><code>LISTEN<\/code><\/strong>\u00a0in the\u00a0<strong>State<\/strong>\u00a0column.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"check-ports-via-nmap-command\">Check Ports via nmap Command<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Nmap utility allows users to scan for open ports on local and remote systems. Execute the command below to scan for all open TCP and UDP ports on the local system:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nmap -n -PN -sT -sU -p- localhost<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The following are the&nbsp;<strong><code>nmap<\/code><\/strong>&nbsp;options used in the example.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>-n<\/code><\/strong>\u00a0\u2013 Skips DNS resolution.<\/li>\n\n\n\n<li><strong><code>-PN<\/code><\/strong>\u00a0\u2013 Skips the discovery phase.<\/li>\n\n\n\n<li><strong><code>-sT<\/code><\/strong>\u00a0and\u00a0<strong><code>-sU<\/code><\/strong>\u00a0\u2013 Tell\u00a0<strong><code>netstat<\/code><\/strong>\u00a0to scan TCP and UDP ports, respectively.<\/li>\n\n\n\n<li><strong><code>-p-<\/code><\/strong>\u00a0\u2013 Scans all the ports.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The output lists the open ports alongside the services that use them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I believe this article will explain and understand to Check Open Ports in Linux.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Network ports are standardized number identifiers that allow devices to use one IP address to handle multiple network requests simultaneously. Since there are 65535 port numbers, keeping a record of which ports are in use can be challenging. Prerequisites What Is a Listening Port? Applications and services use listening ports to listen for incoming network requests. Each listening port is tied to an IP address and a communication protocol such as TCP or UDP. Depending on the network setup, listening ports can be&nbsp;open&nbsp;or&nbsp;closed. One listening port tied can host only one service. For instance, if there is a VPS server on the system that already uses port 80, any other installed hosting server will have to use a different, non-default port number. How to Check Open Ports in Linux? Linux users can check open ports using multiple available networking tools. Each tool displays the same results, but the output format and the amount of information vary. The following sections provide instructions for checking open ports using&nbsp;lsof,&nbsp;netstat,&nbsp;ss,&nbsp;Nmap, and&nbsp;netcat&nbsp;utilities. There are few ways to check Open Ports in Linux below is the most and widely used steps and commands, Check Ports via lsof Command The lsof command allows users to list the programs that utilize listening ports and daemons that maintain active network connections. Use the&nbsp;lsof&nbsp;command to: Display a list of ports in use: The command outputs a list of the connections that use the TCP protocol. Check a specific port number with this syntax: For example, to check if port 32121 is in use, type: If the port is free, the command shows no output. If an application is using the port, the output shows its details: Specify the protocol you wish to scan by adding it to the&nbsp;-i&nbsp;option. For example, to check if the UDP port 83 is open, type: Check Ports via netstat Command The netstat command provides a network activity overview and statistics. Use the command below to display the listening ports on the system with\u00a0netstat: The command uses five command arguments: Identify the listening ports\/sockets by checking the&nbsp;State&nbsp;column and looking for the label&nbsp;LISTENING. Check Ports via ss Command The ss command is a faster and easier-to-use version of the obsolete&nbsp;netstat&nbsp;command. It uses the same options as&nbsp;netstat, but provides more statistics in the output. The following command scans TCP and UDP ports for listening sockets and displays them in a list: The listening ports\/sockets are marked as\u00a0LISTEN\u00a0in the\u00a0State\u00a0column. Check Ports via nmap Command The Nmap utility allows users to scan for open ports on local and remote systems. Execute the command below to scan for all open TCP and UDP ports on the local system: The following are the&nbsp;nmap&nbsp;options used in the example. The output lists the open ports alongside the services that use them. I believe this article will explain and understand to Check Open Ports in Linux.&nbsp;<\/p>\n","protected":false},"author":2,"featured_media":676,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-671","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/comments?post=671"}],"version-history":[{"count":2,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/671\/revisions"}],"predecessor-version":[{"id":677,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/posts\/671\/revisions\/677"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/media\/676"}],"wp:attachment":[{"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/media?parent=671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/categories?post=671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostingpune.co.in\/blog\/wp-json\/wp\/v2\/tags?post=671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}