{"id":146844,"date":"2023-03-14T13:16:29","date_gmt":"2023-03-14T13:16:29","guid":{"rendered":"https:\/\/ded9.com\/?p=146844"},"modified":"2025-11-04T08:32:18","modified_gmt":"2025-11-04T08:32:18","slug":"how-to-show-check-for-open-ports-on-ubuntu-linux","status":"publish","type":"post","link":"https:\/\/ded9.com\/tr\/how-to-show-check-for-open-ports-on-ubuntu-linux\/","title":{"rendered":"How to Show or Check for Open Ports on Ubuntu \/ Linux"},"content":{"rendered":"<p>Port checking is assigned to the specific program currently in use.<\/p>\n<p>Of course, this was just one of many reasons to check open ports before running an application.<\/p>\n<p>For example, you can use the ss command with the -ltmp option to display open ports, including the processes associated with them.<\/p>\n<p><code>sudo ss -ltunp<\/code><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-146845 size-full\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/sudo-ss-ltunp-1024x356-1.webp\" alt=\"For example, you can use the ss command with the -ltmp option to display open ports, including the processes associated with them.\" width=\"1024\" height=\"356\" srcset=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/sudo-ss-ltunp-1024x356-1.webp 1024w, https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/sudo-ss-ltunp-1024x356-1-300x104.webp 300w, https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/sudo-ss-ltunp-1024x356-1-768x267.webp 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>As you can see, port numbers 53 and 631 are open by default and are used for DNS and the Internet. You can decide whether to allow or block these ports.<\/p>\n<h2>1. Using the Nmap command<\/h2>\n<p>Network engineers generally use the Nmap Network Mapper tool to diagnose operating systems, scan ports, and perform network mapping.<\/p>\n<p>Unlike any other tool, nmap can open ports on remote devices without access and does not require root privileges.<\/p>\n<p>But it requires manual installation through the command:<\/p>\n<p><code>sudo apt install nmap<\/code><\/p>\n<p>To check open ports on localhost:<\/p>\n<p><code>nmap localhost<\/code><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-146848 size-full\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/nmap-loclhost-768x269-1.webp\" alt=\"Using the Nmap command\" width=\"768\" height=\"269\" srcset=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/nmap-loclhost-768x269-1.webp 768w, https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/nmap-loclhost-768x269-1-300x105.webp 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/p>\n<p>By default, Nmap only provides information on TCP ports. To list TCP and UDP ports simultaneously, you must use the -sTU option:<\/p>\n<p>Sudo nmap -sTU localhost<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-146851 size-full\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/sudo-nmap-sTU-localhost-768x317-1.webp\" alt=\"By default, Nmap only provides information on TCP ports. To list TCP and UDP ports simultaneously, you must use the -sTU option:\" width=\"768\" height=\"317\" srcset=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/sudo-nmap-sTU-localhost-768x317-1.webp 768w, https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/sudo-nmap-sTU-localhost-768x317-1-300x124.webp 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/p>\n<p>Similarly, you can also use any hostname you want. For example, let&#8217;s go with Google.<\/p>\n<p><code>nmap google.com<\/code><\/p>\n<p>As you can see, Google has closed all unnecessary ports for security reasons.<\/p>\n<h2>2. Check open ports using the lsof command<\/h2>\n<p>Linux works on the philosophy that &#8220;everything is a file,&#8221; and users can list all open files using the lsof command.<\/p>\n<p>Since the lsof tool is required to read data from the proc kernel, you can easily trace network connections, including ports.<\/p>\n<p>But the lsof command cannot be used without options, so you must use special options to get open ports.<\/p>\n<p>So, first let me show you the command,d, and then we will explain:<\/p>\n<p><code>sudo lsof -i -P -sTCP:LISTEN<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-146854 size-full\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/1-1-768x220-1.webp\" alt=\"So, first let me show you the command,d, and then we will explain:\" width=\"768\" height=\"220\" srcset=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/1-1-768x220-1.webp 768w, https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/1-1-768x220-1-300x86.webp 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/p>\n<p>Now, let&#8217;s explain the options used:<\/p>\n<p>It is used to receive files that are only related to the network.<\/p>\n<p>P displays the numerical value of the ports.<\/p>\n<p>sTCP: LISTEN fetches TCP ports in listening (open) mode.<\/p>\n<p>Similarly, you can also check individual ports. So let&#8217;s say I want to check port number 631:<\/p>\n<p><code>sudo lsof -P -i:631<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-146857 size-full\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/2-768x206-1.webp\" alt=\"Similarly, you can also check individual ports. So let's say I want to check port number 631:\" width=\"768\" height=\"206\" srcset=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/2-768x206-1.webp 768w, https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/2-768x206-1-300x80.webp 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/p>\n<p>As you can see, cupsd is used by root on the given port.<\/p>\n<ul>\n<li><a href=\"https:\/\/ded9.com\/what-is-ubuntu-2\/\">What is Ubuntu?<\/a><\/li>\n<\/ul>\n<h2>3. Check the open port using the ss command<\/h2>\n<p>Yes, this is the command I mentioned at the beginning of this tutorial, but I&#8217;ll cover more components here.<\/p>\n<p>So, Socket Statistics is a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Command-line_interface\" target=\"_blank\" rel=\"noopener\">CLI tool<\/a> for getting socket information. As part of the package, you get faster and more in-depth information than anyone else.<\/p>\n<p>To list the ports that are listening, use the following command:<\/p>\n<p><code>sudo ss -tulwnp<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-146860 size-full\" src=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/1232-1024x435-1.webp\" alt=\"To list the ports that are listening, use the following command:\" width=\"1024\" height=\"435\" srcset=\"https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/1232-1024x435-1.webp 1024w, https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/1232-1024x435-1-300x127.webp 300w, https:\/\/ded9.com\/wp-content\/uploads\/2023\/03\/1232-1024x435-1-768x326.webp 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<ul>\n<li>l Used to list open (listening) ports.<\/li>\n<li>t and -u are used to get TCP and UDP ports, respectively.<\/li>\n<li>n indicates the exact amount of bandwidth.<\/li>\n<li>p represents processes using sockets.<\/li>\n<li>w is used to receive raw sockets (sockets that provide access to lower-layer protocols).<\/li>\n<\/ul>\n<p>We have described several methods for listing open ports. I recommend you use the ss command instead of the netstat command, which is deprecated and should no longer be used.<\/p>\n<h2>FAQ<\/h2>\n<div id=\"rank-math-rich-snippet-wrapper\"><div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-1\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How can I check open ports on Ubuntu Linux?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can use the command ss -tuln or netstat -tuln to list open ports and the services using them.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-2\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What tool can I use to scan open ports on my Ubuntu system?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You can use nmap to scan your system: sudo nmap -sT -O localhost.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-3\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do I check which process is using a specific port in Ubuntu?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Run sudo lsof -i :PORT_NUMBER or sudo netstat -tulpn | grep PORT_NUMBER to see the process linked to that port.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Port checking is assigned to the specific program currently in use. Of course, this was just one of many reasons to check open ports before running an application. For example, you can use the ss command with the -ltmp option to display open ports, including the processes associated with them. sudo ss -ltunp As you [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":146863,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[86],"tags":[934,961],"class_list":["post-146844","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-server","tag-ubuntu"],"acf":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts\/146844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/comments?post=146844"}],"version-history":[{"count":6,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts\/146844\/revisions"}],"predecessor-version":[{"id":264819,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/posts\/146844\/revisions\/264819"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/media\/146863"}],"wp:attachment":[{"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/media?parent=146844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/categories?post=146844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ded9.com\/tr\/wp-json\/wp\/v2\/tags?post=146844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}