{"id":1164,"date":"2018-10-22T17:07:06","date_gmt":"2018-10-22T17:07:06","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=1164"},"modified":"2018-10-23T00:25:03","modified_gmt":"2018-10-23T00:25:03","slug":"how-to-check-list-of-opened-and-closed-port-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/22\/how-to-check-list-of-opened-and-closed-port-in-linux\/","title":{"rendered":"how to check list of opened and closed port in linux ?"},"content":{"rendered":"<p>There are different commands on both Linux and UNIX server to see what TCP\/UDP ports are listening or open on your server. You can use netstat command, which prints network connections, routing tables, interface statistics, masquerade connections, and multicast memberships, etc.<\/p>\n<p><b>Method 1:<\/b><\/p>\n<p><b>netstat command to find open ports<\/b><\/p>\n<p>ravi@linuxforfreshers.com&gt;&gt;sudo netstat &#8211;listen<\/p>\n<p>Active Internet connections (only servers)<\/p>\n<p>Proto Recv-Q Send-Q Local Address Foreign Address State<\/p>\n<p>tcp 0 0 *:1234 *:* LISTEN<\/p>\n<p>tcp 0 0 *:8084 *:* LISTEN<\/p>\n<p>tcp 0 0 192.168.122.1:domain *:* LISTEN<\/p>\n<p>tcp 0 0 *:ssh *:* LISTEN<\/p>\n<p>tcp 0 0 *:ipp *:* LISTEN<\/p>\n<p>tcp 0 0 *:microsoft-ds *:* LISTEN<\/p>\n<p>tcp 0 0 *:7070 *:* LISTEN<\/p>\n<p>tcp 0 0 localhost:mysql *:* LISTEN<\/p>\n<p>tcp 0 0 *:netbios-ssn *:* LISTEN<\/p>\n<p>tcp6 0 0 [::]:ssh [::]:* LISTEN<\/p>\n<p>tcp6 0 0 [::]:ipp [::]:* LISTEN<\/p>\n<p>tcp6 0 0 [::]:microsoft-ds [::]:* LISTEN<\/p>\n<p>tcp6 0 0 [::]:netbios-ssn [::]:* LISTEN<\/p>\n<p>udp 0 0 *:39505 *:*<\/p>\n<p>udp 0 0 *:ipp *:*<\/p>\n<p>udp 0 0 *:mdns *:*<\/p>\n<p>udp 0 0 *:mdns *:*<\/p>\n<p>Active UNIX domain sockets (only servers)<\/p>\n<p>Proto RefCnt Flags Type State I-Node Path<\/p>\n<p>unix 2 [ ACC ] STREAM LISTENING 12950 \/var\/run\/acpid.socket<\/p>\n<p>unix 2 [ ACC ] STREAM LISTENING 18259042 @atpl-com.canonical.Unity.Scope.rhythmbox.T516689809663571<\/p>\n<p>unix 2 [ ACC ] STREAM LISTENING 19096 \/run\/user\/1000\/keyring-n7CcyZ\/control<\/p>\n<p>unix 2 [ ACC ] STREAM LISTENING 22589 @\/tmp\/.ICE-unix\/3779<\/p>\n<p>unix 2 [ ACC ] STREAM LISTENING 21540 @\/tmp\/dbus-u6IauIGH5I<\/p>\n<p><b>To display open ports and established TCP connections, enter:<\/b><\/p>\n<p>Active Internet connections (servers and established)<\/p>\n<p>Proto Recv-Q Send-Q Local Address Foreign Address State<\/p>\n<p>tcp 0 0 0.0.0.0:1234 0.0.0.0:* LISTEN<\/p>\n<p>tcp 0 0 0.0.0.0:8084 0.0.0.0:* LISTEN<\/p>\n<p>tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN<\/p>\n<p>tcp 0 0 0.0.0.0:631 0.0.0.0:* LISTEN<\/p>\n<p>tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN<\/p>\n<p>tcp 0 0 0.0.0.0:7070 0.0.0.0:* LISTEN<\/p>\n<p><b>To display only open UDP ports try the following command:<\/b><\/p>\n<p>ravi@linuxforfreshers.com&gt;&gt;sudo netstat -vaun<\/p>\n<p>Active Internet connections (servers and established)<\/p>\n<p>Proto Recv-Q Send-Q Local Address Foreign Address State<\/p>\n<p>udp 0 0 0.0.0.0:39505 0.0.0.0:*<\/p>\n<p>udp 0 0 0.0.0.0:631 0.0.0.0:*<\/p>\n<p>\u25cf -l = only services which are listening on some port<\/p>\n<p>\u25cf -n = show port number, don&#8217;t try to resolve the service name<\/p>\n<p>\u25cf -p = name of the program<\/p>\n<p>To display the list of open ports, enter:<\/p>\n<p>To display all open files, use:<\/p>\n<p>To display all open IPv4 network files in use by the process whose PID is 10050, use:<\/p>\n<p><b># lsof -iTCP -sTCP:LISTEN<\/b><\/p>\n<p>Quickest way to test if a TCP port is open (including any hardware firewalls you may have), is to type, from a remote computer (e.g. your desktop):<\/p>\n<p><b>telnet hostip port_number<\/b><\/p>\n<p>ravi@linuxforfreshers.com&gt;&gt;telnet 192.168.101.156 22<\/p>\n<p>Trying 192.168.101.156&#8230;<\/p>\n<p>Connected to 192.168.101.156<\/p>\n<p>Escape character is &#8216;^]&#8217;.<\/p>\n<p>ravi@linuxforfreshers.com&gt;&gt;telnet localhost 22<\/p>\n<p>ravi@linuxforfreshers.com&gt;&gt;ss -lntu<\/p>\n<p>Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port<\/p>\n<p>tcp UNCONN 0 0 *:39505 *:*<\/p>\n<p>tcp UNCONN 0 0 *:631 *:*<\/p>\n<p>tcp UNCONN 0 0 *:5353 *:*<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.linuxforfreshers.com\/2017\/06\/how-to-check-list-of-opened-and-closed.html\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are different commands on both Linux and UNIX server to see what TCP\/UDP ports are listening or open on your server. You can use netstat command, which prints network connections, routing tables, interface statistics, masquerade connections, and multicast memberships, etc. Method 1: netstat command to find open ports ravi@linuxforfreshers.com&gt;&gt;sudo netstat &#8211;listen Active Internet connections &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/22\/how-to-check-list-of-opened-and-closed-port-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;how to check list of opened and closed port 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-1164","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\/1164","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=1164"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1164\/revisions"}],"predecessor-version":[{"id":1279,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1164\/revisions\/1279"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=1164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=1164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=1164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}