{"id":12447,"date":"2019-03-27T01:27:24","date_gmt":"2019-03-27T01:27:24","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12447"},"modified":"2019-03-27T01:27:24","modified_gmt":"2019-03-27T01:27:24","slug":"4-ways-to-find-out-what-ports-are-listening-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/27\/4-ways-to-find-out-what-ports-are-listening-in-linux\/","title":{"rendered":"4 Ways to Find Out What Ports Are Listening in Linux"},"content":{"rendered":"<p>The state of a port is either\u00a0<strong>open<\/strong>,\u00a0<strong>filtered<\/strong>,\u00a0<strong>closed<\/strong>, or\u00a0<strong>unfiltered<\/strong>. A port is said to be open if an application on the target machine is listening for connections\/packets on that port.<\/p>\n<p>In this article, we will explain four ways to check open ports and also will show you how to find which application is listening on what port in Linux.<\/p>\n<h3>1. Using Netstat Command<\/h3>\n<p><a href=\"https:\/\/www.tecmint.com\/20-netstat-commands-for-linux-network-management\/\" target=\"_blank\" rel=\"noopener\">Netstat<\/a>\u00a0is a widely used tool for querying information about the Linux networking subsystem. You can use it to print all open ports like this:<\/p>\n<pre>$ sudo netstat -ltup \r\n<\/pre>\n<p>The flag\u00a0<code>-l<\/code>\u00a0tells netstat to print all listening sockets,\u00a0<code>-t<\/code>\u00a0shows all TCP connections,\u00a0<code>-u<\/code>\u00a0displays all UDP connections and\u00a0<code>-p<\/code>\u00a0enables printing of application\/program name listening on the port.<\/p>\n<div id=\"attachment_31056\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/check-open-ports-using-netstat.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31056\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/check-open-ports-using-netstat.png\" sizes=\"auto, (max-width: 1032px) 100vw, 1032px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/check-open-ports-using-netstat.png 1032w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/check-open-ports-using-netstat-768x383.png 768w\" alt=\"Check Open Ports Using Netstat Command\" width=\"1032\" height=\"515\" aria-describedby=\"caption-attachment-31056\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31056\" class=\"wp-caption-text\">Check Open Ports Using Netstat Command<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<p>To print numeric values rather than service names, add the\u00a0<code>-n<\/code>\u00a0flag.<\/p>\n<pre>$ sudo netstat -lntup\r\n<\/pre>\n<div id=\"attachment_31057\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/show-numeric-values-instead-of-service-names.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31057\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/show-numeric-values-instead-of-service-names.png\" sizes=\"auto, (max-width: 1032px) 100vw, 1032px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/show-numeric-values-instead-of-service-names.png 1032w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/show-numeric-values-instead-of-service-names-768x383.png 768w\" alt=\"Show Numeric Values\" width=\"1032\" height=\"515\" aria-describedby=\"caption-attachment-31057\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31057\" class=\"wp-caption-text\">Show Numeric Values<\/p>\n<\/div>\n<p>You can also use\u00a0<a href=\"https:\/\/www.tecmint.com\/12-practical-examples-of-linux-grep-command\/\" target=\"_blank\" rel=\"noopener\">grep command<\/a>\u00a0to find out which application is listening on a particular port, for example.<\/p>\n<pre>$ sudo netstat -lntup | grep \"nginx\"\r\n<\/pre>\n<div id=\"attachment_31058\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/Find-Port-of-Application.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31058\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/Find-Port-of-Application.png\" sizes=\"auto, (max-width: 1032px) 100vw, 1032px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/Find-Port-of-Application.png 1032w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/Find-Port-of-Application-768x86.png 768w\" alt=\"Find Port of Running Application\" width=\"1032\" height=\"116\" aria-describedby=\"caption-attachment-31058\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31058\" class=\"wp-caption-text\">Find Port of Running Application<\/p>\n<\/div>\n<p>Alternatively, you can specify the port and find the application bound to, as shown.<\/p>\n<pre>$ sudo netstat -lntup | grep \":80\"\r\n<\/pre>\n<div id=\"attachment_31059\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/discover-application-using-a-port.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31059\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/discover-application-using-a-port.png\" sizes=\"auto, (max-width: 1002px) 100vw, 1002px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/discover-application-using-a-port.png 1002w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/discover-application-using-a-port-768x60.png 768w\" alt=\"Find Application Using a Port Number\" width=\"1002\" height=\"78\" aria-describedby=\"caption-attachment-31059\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31059\" class=\"wp-caption-text\">Find Application Using a Port Number<\/p>\n<\/div>\n<h3>2. Using ss Command<\/h3>\n<p><strong>ss<\/strong>\u00a0is another useful tool for displaying information about sockets. It\u2019s output looks similar to that of\u00a0<strong>netstat<\/strong>. The following command will show all listening ports for\u00a0<strong>TCP<\/strong>\u00a0and\u00a0<strong>UDP<\/strong>\u00a0connections in numeric value.<\/p>\n<pre>$ sudo ss -lntu\r\n<\/pre>\n<div id=\"attachment_31060\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/find-open-ports-using-ss-command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31060\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/find-open-ports-using-ss-command.png\" sizes=\"auto, (max-width: 1412px) 100vw, 1412px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/find-open-ports-using-ss-command.png 1412w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/find-open-ports-using-ss-command-768x270.png 768w\" alt=\"Find Open Ports Using ss Command\" width=\"1412\" height=\"496\" aria-describedby=\"caption-attachment-31060\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31060\" class=\"wp-caption-text\">Find Open Ports Using ss Command<\/p>\n<\/div>\n<h3>3. Using Nmap Command<\/h3>\n<p><a href=\"https:\/\/www.tecmint.com\/nmap-command-examples\/\" target=\"_blank\" rel=\"noopener\">Nmap<\/a>\u00a0is a powerful and popular network exploration tool and port scanner. To install nmap on your system, use your default package manager as shown.<\/p>\n<pre>$ sudo apt install nmap  [On Debian\/Ubuntu]\r\n$ sudo yum install nmap  [On CentOS\/RHEL]\r\n$ sudo dnf install nmap  [On Fedora 22+]\r\n<\/pre>\n<p>To scan all open\/listening ports in your Linux system, run the following command (which should take a long time to complete).<\/p>\n<pre>$ sudo nmap -n -PN -sT -sU -p- localhost\r\n<\/pre>\n<h3>4. Using lsof Command<\/h3>\n<p>The final tool we will cover for querying open ports is\u00a0<a href=\"https:\/\/www.tecmint.com\/10-lsof-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">lsof command<\/a>, which is used to list open files in Linux. Since\u00a0<a href=\"https:\/\/www.tecmint.com\/explanation-of-everything-is-a-file-and-types-of-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">everything is a file in Unix\/Linux<\/a>, an open file may be a stream or a network file.<\/p>\n<p>To list all Internet and network files, use the\u00a0<code>-i<\/code>\u00a0option. Note that this command shows a mix of service names and numeric ports.<\/p>\n<pre>$ sudo lsof -i\r\n<\/pre>\n<div id=\"attachment_31061\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/list-open-network-files-using-lsof.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31061\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/list-open-network-files-using-lsof.png\" sizes=\"auto, (max-width: 822px) 100vw, 822px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/list-open-network-files-using-lsof.png 822w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/list-open-network-files-using-lsof-768x446.png 768w\" alt=\"List Open Network Files Using lsof Command\" width=\"822\" height=\"477\" aria-describedby=\"caption-attachment-31061\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31061\" class=\"wp-caption-text\">List Open Network Files Using lsof Command<\/p>\n<\/div>\n<p>To find which application is listening on a particular port, run\u00a0<strong>lsof<\/strong>\u00a0in this form.<\/p>\n<pre>$ sudo lsof -i :80\r\n<\/pre>\n<div id=\"attachment_31062\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/lsof-specify-port-to-find-application.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31062\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/lsof-specify-port-to-find-application.png\" sizes=\"auto, (max-width: 772px) 100vw, 772px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/lsof-specify-port-to-find-application.png 772w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/11\/lsof-specify-port-to-find-application-768x248.png 768w\" alt=\"Find Application Using Port\" width=\"772\" height=\"249\" aria-describedby=\"caption-attachment-31062\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31062\" class=\"wp-caption-text\">Find Application Using Port<\/p>\n<\/div>\n<p>That\u2019s all! In this article, we have explained four ways to check open ports in Linux. We also showed how to check which processes are bound upon particular ports. You can share your thoughts or ask any questions via the feedback form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/find-listening-ports-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The state of a port is either\u00a0open,\u00a0filtered,\u00a0closed, or\u00a0unfiltered. A port is said to be open if an application on the target machine is listening for connections\/packets on that port. In this article, we will explain four ways to check open ports and also will show you how to find which application is listening on what &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/27\/4-ways-to-find-out-what-ports-are-listening-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;4 Ways to Find Out What Ports Are Listening in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12447","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12447"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12447\/revisions"}],"predecessor-version":[{"id":12448,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12447\/revisions\/12448"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}