{"id":448,"date":"2024-08-23T11:30:51","date_gmt":"2024-08-23T11:30:51","guid":{"rendered":"https:\/\/249host.com\/tutorials\/?p=448"},"modified":"2024-08-23T11:31:42","modified_gmt":"2024-08-23T11:31:42","slug":"how-to-check-open-ports-in-linux","status":"publish","type":"post","link":"https:\/\/249host.com\/tutorials\/how-to-check-open-ports-in-linux\/","title":{"rendered":"How to Check Open Ports in Linux"},"content":{"rendered":"<p><span id=\"span-87-157\" class=\"ct-span oxy-stock-content-styles\"><strong>This article will teach you how to Check Open Ports in Linux on a Linux system using popular networking tools.<\/strong><\/span><\/p>\n<h2 id=\"ftoc-heading-1\" class=\"wp-block-heading ftwp-heading\">What Is a Listening Port?<\/h2>\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<p>Depending on the network setup, listening ports can be <strong>open <\/strong>or <strong>closed<\/strong>.<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>Open ports<\/strong> accept outside connections using the correct protocol.<\/li>\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<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<h2 id=\"ftoc-heading-2\" class=\"wp-block-heading ftwp-heading\">How to Check Open Ports in Linux?<\/h2>\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<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<p>There are few ways to check Open Ports in <a href=\"https:\/\/www.squarebrothers.com\/\" target=\"_blank\" rel=\"noopener\">Linux<\/a> below is the most and widely used steps and commands,<\/p>\n<h3 id=\"ftoc-heading-3\" class=\"wp-block-heading ftwp-heading\">Check Ports via lsof Command<\/h3>\n<p>The lsof command allows users to list the programs that utilize listening ports and daemons that maintain active network connections.<\/p>\n<p>Use the <strong><code>lsof<\/code><\/strong> command to:<\/p>\n<p>Display a list of ports in use:<\/p>\n<pre>sudo lsof -nP -iTCP -sTCP:LISTEN<\/pre>\n<p><span id=\"span-87-157\" class=\"ct-span oxy-stock-content-styles\">The command outputs a list of the connections that use the TCP protocol.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-455 size-full\" src=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/sshport.png\" alt=\"Check Open Ports in Linux\" width=\"766\" height=\"196\" srcset=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/sshport.png 766w, https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/sshport-300x77.png 300w\" sizes=\"auto, (max-width: 766px) 100vw, 766px\" \/><\/p>\n<p><span id=\"span-87-157\" class=\"ct-span oxy-stock-content-styles\">Check a specific port number with this syntax:<\/span><\/p>\n<pre>sudo lsof -nP -i:[port-number]<\/pre>\n<p><span id=\"span-87-157\" class=\"ct-span oxy-stock-content-styles\">For example, to check if port 32121 is in use, type:<\/span><\/p>\n<pre>sudo lsof -nP -i:32121<\/pre>\n<p><span id=\"span-87-157\" class=\"ct-span oxy-stock-content-styles\">If the port is free, the command shows no output. If an application is using the port, the output shows its details:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-450 size-full\" src=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/32121.png\" alt=\"Check Open Ports in Linux\" width=\"881\" height=\"113\" srcset=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/32121.png 881w, https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/32121-300x38.png 300w, https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/32121-768x99.png 768w\" sizes=\"auto, (max-width: 881px) 100vw, 881px\" \/><\/p>\n<p>Specify the protocol you wish to scan by adding it to the <strong><code>-i<\/code><\/strong> option.<\/p>\n<p>For example, to check if the UDP port 83 is open, type:<\/p>\n<pre>sudo lsof -nP -iUDP:83<\/pre>\n<h3 id=\"ftoc-heading-4\" class=\"wp-block-heading ftwp-heading\">Check Ports via netstat Command<\/h3>\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<pre>sudo netstat -tunpl<\/pre>\n<p>The command uses five command arguments:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong><code>-t<\/code><\/strong> &#8211; Queries the command for TCP ports.<\/li>\n<li><strong><code>-u<\/code><\/strong> &#8211; Queries for UDP ports.<\/li>\n<li><strong><code>-n<\/code><\/strong> &#8211; Avoids DNS lookup and shows only IP addresses to speed up the process.<\/li>\n<li><strong><code>-p<\/code><\/strong> &#8211; Displays the process ID and the name of the program using the port.<\/li>\n<li><strong><code>-l<\/code><\/strong> &#8211; Outputs listening ports.<\/li>\n<\/ul>\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<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-451 aligncenter\" src=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/tunpl.png\" alt=\"\" width=\"888\" height=\"242\" srcset=\"https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/tunpl.png 888w, https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/tunpl-300x82.png 300w, https:\/\/249host.com\/tutorials\/wp-content\/uploads\/2024\/08\/tunpl-768x209.png 768w\" sizes=\"auto, (max-width: 888px) 100vw, 888px\" \/><\/p>\n<h3 id=\"ftoc-heading-5\" class=\"wp-block-heading ftwp-heading\">Check Ports via ss Command<\/h3>\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<p>The following command scans TCP and UDP ports for listening sockets and displays them in a list:<\/p>\n<pre>sudo ss -tunl<\/pre>\n<p><span id=\"span-87-157\" class=\"ct-span oxy-stock-content-styles\">The listening ports\/sockets are marked as <strong><code>LISTEN<\/code><\/strong> in the <strong>State<\/strong> column.<\/span><\/p>\n<h3 id=\"ftoc-heading-6\" class=\"wp-block-heading ftwp-heading\">Check Ports via nmap Command<\/h3>\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<pre>sudo nmap -n -PN -sT -sU -p- localhost<\/pre>\n<p>The following are the <strong><code>nmap<\/code><\/strong> options used in the example.<\/p>\n<ul class=\"wp-block-list\">\n<li><strong><code>-n<\/code><\/strong> &#8211; Skips DNS resolution.<\/li>\n<li><strong><code>-PN<\/code><\/strong> &#8211; Skips the discovery phase.<\/li>\n<li><strong><code>-sT<\/code><\/strong> and <strong><code>-sU<\/code><\/strong> &#8211; Tell <strong><code>netstat<\/code><\/strong> to scan TCP and UDP ports, respectively.<\/li>\n<li><strong><code>-p-<\/code><\/strong> &#8211; Scans all the ports.<\/li>\n<\/ul>\n<p>The output lists the open ports alongside the services that use them.<\/p>\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:\/\/249host.com\/tutorials\/centos-vs-almalinux-a-comparison\/\">centos Vs Almalinux.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article will teach you how to Check Open Ports in Linux on a Linux system using popular networking tools. 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. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,10,1],"tags":[57,47,56],"class_list":["post-448","post","type-post","status-publish","format-standard","hentry","category-control-panel","category-general","category-linux","tag-listen","tag-tcp","tag-udp"],"_links":{"self":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts\/448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/comments?post=448"}],"version-history":[{"count":11,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts\/448\/revisions"}],"predecessor-version":[{"id":462,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/posts\/448\/revisions\/462"}],"wp:attachment":[{"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/media?parent=448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/categories?post=448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/249host.com\/tutorials\/wp-json\/wp\/v2\/tags?post=448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}