{"id":662,"date":"2024-08-28T01:34:41","date_gmt":"2024-08-28T01:34:41","guid":{"rendered":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/?p=662"},"modified":"2024-08-28T08:24:34","modified_gmt":"2024-08-28T08:24:34","slug":"how-to-check-open-ports-linux","status":"publish","type":"post","link":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/how-to-check-open-ports-linux\/","title":{"rendered":"How to Check Open Ports in Linux"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"introduction\">Introduction<\/h2>\n\n\n\n<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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h3>\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=\"#introduction\">Introduction<\/a><ul><li><a href=\"#prerequisites\">Prerequisites<\/a><\/li><\/ul><\/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><ul><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><\/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>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>Depending on the network setup, listening ports can be <strong>open <\/strong>or <strong>closed<\/strong>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Open ports<\/strong> accept outside connections using the correct protocol.<\/li>\n\n\n\n<li><strong>Closed ports<\/strong> do 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>One listening port tied can host only one service. For instance, if there is a web server on the system that already uses port 80, any other installed web server 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>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>The following sections provide instructions for checking open ports using <strong>lsof<\/strong>, <strong>netstat<\/strong>, <strong>ss<\/strong>, <strong>Nmap<\/strong>, and <strong>netcat <\/strong>utilities.<\/p>\n\n\n\n<p>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<h3 class=\"wp-block-heading\" id=\"check-ports-via-lsof-command\">Check Ports via lsof Command<\/h3>\n\n\n\n<p>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>Use the <strong><code>lsof<\/code><\/strong> command to:<\/p>\n\n\n\n<p>Display a list of ports in use:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo lsof -nP -iTCP -sTCP:LISTEN<\/pre>\n\n\n\n<p>The command outputs a list of the connections that use the TCP protocol.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/sshport.png\" alt=\"Check Open Ports in Linux\" class=\"wp-image-455\"\/><\/figure><\/div>\n\n\n<p>Check a specific port number with this syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo lsof -nP -i:[port-number]<\/pre>\n\n\n\n<p>For example, to check if port 32121 is in use, type:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo lsof -nP -i:32121<\/pre>\n\n\n\n<p>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<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/32121.png\" alt=\"Check Open Ports in Linux\" class=\"wp-image-450\"\/><\/figure><\/div>\n\n\n<p>Specify the protocol you wish to scan by adding it to the <strong><code>-i<\/code><\/strong> option.<\/p>\n\n\n\n<p>For example, to check if the UDP port 83 is open, type:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo lsof -nP -iUDP:83<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"check-ports-via-netstat-command\">Check Ports via netstat Command<\/h3>\n\n\n\n<p>The netstat command provides a network activity overview and statistics. Use the command below to display the listening ports on the system with <strong><code>netstat<\/code><\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo netstat -tunpl<\/pre>\n\n\n\n<p>The command uses five command arguments:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>-t<\/code><\/strong> \u2013 Queries the command for TCP ports.<\/li>\n\n\n\n<li><strong><code>-u<\/code><\/strong> \u2013 Queries for UDP ports.<\/li>\n\n\n\n<li><strong><code>-n<\/code><\/strong> \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> \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> \u2013 Outputs listening ports.<\/li>\n<\/ul>\n\n\n\n<p>Identify the listening ports\/sockets by checking the <strong><code>State<\/code><\/strong> column and looking for the label <strong><code>LISTENING<\/code><\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/tunpl.png\" alt=\"\" class=\"wp-image-451\"\/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"check-ports-via-ss-command\">Check Ports via ss Command<\/h3>\n\n\n\n<p>The ss command is a faster and easier-to-use version of the obsolete <strong><code>netstat<\/code><\/strong> command. It uses the same options as <strong><code>netstat<\/code><\/strong>, but provides more statistics in the output.<\/p>\n\n\n\n<p>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-preformatted\">sudo ss -tunl<\/pre>\n\n\n\n<p>The listening ports\/sockets are marked as <strong><code>LISTEN<\/code><\/strong> in the <strong>State<\/strong> column.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"check-ports-via-nmap-command\">Check Ports via nmap Command<\/h3>\n\n\n\n<p>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-preformatted\">sudo nmap -n -PN -sT -sU -p- localhost<\/pre>\n\n\n\n<p>The following are the <strong><code>nmap<\/code><\/strong> options used in the example.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>-n<\/code><\/strong> \u2013 Skips DNS resolution.<\/li>\n\n\n\n<li><strong><code>-PN<\/code><\/strong> \u2013 Skips the discovery phase.<\/li>\n\n\n\n<li><strong><code>-sT<\/code><\/strong> and <strong><code>-sU<\/code><\/strong> \u2013 Tell <strong><code>netstat<\/code><\/strong> to scan TCP and UDP ports, respectively.<\/li>\n\n\n\n<li><strong><code>-p-<\/code><\/strong> \u2013 Scans all the ports.<\/li>\n<\/ul>\n\n\n\n<p>The output lists the open ports alongside the services that use them.<\/p>\n\n\n\n<p>I believe this article will explain and understand to Check Open Ports in Linux. We know that centos support is end of line, let know the comparison between <a href=\"https:\/\/www.cpanelresellerwebhosting.in\" data-type=\"link\" data-id=\"https:\/\/www.cpanelresellerwebhosting.in\">centos <\/a><a href=\"https:\/\/www.cpanelresellerwebhosting.in\/vps-hosting\/\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/www.cpanelresellerwebhosting.in\" rel=\"noreferrer noopener nofollow\">Vs <\/a><a href=\"https:\/\/www.cpanelresellerwebhosting.in\" data-type=\"link\" data-id=\"https:\/\/www.cpanelresellerwebhosting.in\">Almalinux.<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.facebook.com\/sharer.php?u=https:\/\/249host.com\/tutorials\/how-to-check-open-ports-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><a href=\"https:\/\/twitter.com\/share?url=https:\/\/249host.com\/tutorials\/how-to-check-open-ports-in-linux\/&amp;text=How%20to%20Check%20Open%20Ports%20in%20Linux\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"> <\/a><a href=\"mailto:?subject=How%20to%20Check%20Open%20Ports%20in%20Linux&amp;body=https:\/\/249host.com\/tutorials\/how-to-check-open-ports-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><a href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=https:\/\/249host.com\/tutorials\/how-to-check-open-ports-in-linux\/&amp;title=How%20to%20Check%20Open%20Ports%20in%20Linux\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"> <\/a><a href=\"javascript:pinIt();\"><\/a><a href=\"https:\/\/t.me\/share\/url?url=https:\/\/249host.com\/tutorials\/how-to-check-open-ports-in-linux\/&amp;title=How%20to%20Check%20Open%20Ports%20in%20Linux\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"> <\/a><a href=\"https:\/\/api.whatsapp.com\/send?text=https:\/\/249host.com\/tutorials\/how-to-check-open-ports-in-linux\/&amp;title=How%20to%20Check%20Open%20Ports%20in%20Linux\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"><\/a><a href=\"https:\/\/www.reddit.com\/submit?url=https:\/\/249host.com\/tutorials\/how-to-check-open-ports-in-linux\/&amp;title=How%20to%20Check%20Open%20Ports%20in%20Linux\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"> <\/a><a href=\"javascript:window.print()\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Network ports are standardized number identifiers that allow devices to use one IP address&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-662","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/662"}],"collection":[{"href":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=662"}],"version-history":[{"count":5,"href":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/662\/revisions"}],"predecessor-version":[{"id":667,"href":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/662\/revisions\/667"}],"wp:attachment":[{"href":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cpanelresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}