{"id":4706,"date":"2024-09-25T15:40:39","date_gmt":"2024-09-25T18:40:39","guid":{"rendered":"https:\/\/tpinformatica.com.br\/site\/?p=4706"},"modified":"2024-09-26T14:31:37","modified_gmt":"2024-09-26T17:31:37","slug":"como-verificar-portas-abertas-no-linux-guia-completo-e-passo-a-passo","status":"publish","type":"post","link":"https:\/\/tpinformatica.com.br\/site\/como-verificar-portas-abertas-no-linux-guia-completo-e-passo-a-passo\/","title":{"rendered":"Como Verificar Portas Abertas no Linux: Guia Completo e Passo a Passo"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Tabela de conte\u00fados (\u00cdndice)<\/h2><nav><div><div class=\"\"><a href=\"#inspecao-de-portas-abertas\">Inspe\u00e7\u00e3o de Portas Abertas<\/a><div><div class=\"\"><a href=\"#comando-lsof-no-linux\">Comando lsof no Linux<\/a><\/div><div class=\"\"><a href=\"#comando-fuser-no-linux\">Comando fuser no Linux<\/a><\/div><\/div><\/div><\/div><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"inspecao-de-portas-abertas\">Inspe\u00e7\u00e3o de Portas Abertas<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Verificar portas abertas com o&nbsp;<strong><a href=\"https:\/\/pt.wikipedia.org\/wiki\/Utilit%C3%A1rios_Unix\" rel=\"nofollow noopener\" target=\"_blank\">netstat<\/a><\/strong>, as op\u00e7\u00f5es \u201c-tunl\u201d podem ser usadas:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&nbsp;<strong>-t<\/strong>&nbsp;para TCP<\/li>\n\n\n\n<li><strong>-u<\/strong>&nbsp;para UDP<\/li>\n\n\n\n<li><strong>-n<\/strong>&nbsp;para n\u00e3o resolver nomes<\/li>\n\n\n\n<li><strong>-l<\/strong>&nbsp;para as portas abertas (listen)<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-1024x512.png\" alt=\"Empresa de Suporte em T.I Empresa de tecnologia da informa\u00e7\u00e3o\" class=\"wp-image-4394\" title=\"\" srcset=\"https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-1024x512.png 1024w, https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-300x150.png 300w, https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-768x384.png 768w, https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-1536x768.png 1536w, https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-2048x1024.png 2048w, https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-150x75.png 150w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Neste exemplo, o netstat lista as portas abertas TCP\/UDP:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ netstat -tunl<br>Active Internet connections (only servers)<br>Proto  Local Address&nbsp; &nbsp;Foreign Address<br>tcp&nbsp; &nbsp; 127.0.0.53:53&nbsp; &nbsp;0.0.0.0:*&nbsp;<br>tcp&nbsp; &nbsp; 0.0.0.0:22&nbsp; &nbsp; &nbsp; 0.0.0.0:*<br>tcp6&nbsp; &nbsp;0 :::22&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:::*&nbsp;&nbsp;<br>udp&nbsp; &nbsp; 127.0.0.53:53&nbsp; &nbsp;0.0.0.0:*<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">O netstat com a op\u00e7\u00e3o -p mostra os processos donos das portas. Para utilizar essa op\u00e7\u00e3o \u00e9 preciso ser o root:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo netstat -tunlp<br>Active Internet connections (only servers)<br>Proto  Local Address&nbsp; &nbsp;State&nbsp; &nbsp;PID\/Program name&nbsp; &nbsp;&nbsp;<br>tcp&nbsp; &nbsp; 127.0.0.53:53&nbsp; &nbsp;LISTEN&nbsp; 24813\/systemd-resol&nbsp;<br>tcp&nbsp; &nbsp; 0.0.0.0:22&nbsp; &nbsp; &nbsp; LISTEN&nbsp;  9857\/sshd&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>tcp6&nbsp; &nbsp;:::22&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LISTEN&nbsp;  9857\/sshd&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>udp&nbsp; &nbsp; 127.0.0.53:53&nbsp; &nbsp;      &nbsp; 24813\/systemd-resol&nbsp;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">O&nbsp;<a href=\"https:\/\/pt.wikipedia.org\/wiki\/Utilit%C3%A1rios_Unix\" rel=\"nofollow noopener\" target=\"_blank\">comando ss<\/a>&nbsp;tamb\u00e9m pode mostrar as portas abertas com a op\u00e7\u00e3o id\u00eantica:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-1024x512.png\" alt=\"Empresa de Suporte em T.I Empresa de tecnologia da informa\u00e7\u00e3o\" class=\"wp-image-4394\" title=\"\" srcset=\"https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-1024x512.png 1024w, https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-300x150.png 300w, https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-768x384.png 768w, https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-1536x768.png 1536w, https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-2048x1024.png 2048w, https:\/\/tpinformatica.com.br\/site\/wp-content\/uploads\/2024\/02\/Suporte-em-TI-150x75.png 150w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"># ss -tunelp<br>Netid&nbsp; Local Address:Port&nbsp; Peer Address:Port&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>udp&nbsp; &nbsp; 127.0.0.53%lo:53&nbsp; &nbsp; 0.0.0.0:*&nbsp; &nbsp;(\"systemd-resolve\",pid=355)<br>udp&nbsp; &nbsp; 0.0.0.0:68&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.0.0.0:*&nbsp; &nbsp;(\"dhclient\",pid=17984)<br>udp&nbsp; &nbsp; 0.0.0.0:5353&nbsp; &nbsp; &nbsp; &nbsp; 0.0.0.0:*&nbsp; &nbsp;(\"avahi-daemon\",pid=27533)<br>tcp&nbsp; &nbsp; 0.0.0.0:22&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.0.0.0:*&nbsp; &nbsp;(\"sshd\",pid=14825)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"comando-lsof-no-linux\">Comando <a href=\"https:\/\/man7.org\/linux\/man-pages\/man8\/lsof.8.html\" rel=\"nofollow noopener\" target=\"_blank\">lsof<\/a> no <a href=\"https:\/\/tpinformatica.com.br\/site\/time-de-placa-de-rede-no-linux-debian\/\" data-type=\"post\" data-id=\"3743\">Linux<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Como tudo no Linux \u00e9 um arquivo, tamb\u00e9m as conex\u00f5es de rede podem ser visualizadas como um \u201carquivo em aberto\u201d. O comando \u201clsof\u201d pode ser usado neste contexto para ver os arquivos que correspondem a endere\u00e7os de Internet.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A op\u00e7\u00e3o \u201c-i\u201d do lsof filtra os arquivos em aberto do tipo de endere\u00e7os de Internet. \u00c9 necess\u00e1rio executar o lsof como root:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo lsof -i\nCOMMAND&nbsp; &nbsp; &nbsp;PID&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; USER&nbsp; &nbsp;FD&nbsp; &nbsp;TYPE  NODE NAME\nsshd&nbsp; &nbsp; &nbsp; &nbsp;9857&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root&nbsp; &nbsp; 3u&nbsp; IPv4&nbsp; TCP *:ssh (LISTEN)\nsshd&nbsp; &nbsp; &nbsp; &nbsp;9857&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root&nbsp; &nbsp; 4u&nbsp; IPv6&nbsp; TCP *:ssh (LISTEN)\nsystemd-r 24813 systemd-resolve&nbsp; &nbsp;12u&nbsp; IPv4&nbsp; UDP localhost:domain&nbsp;\nsystemd-r 24813 systemd-resolve&nbsp; &nbsp;13u&nbsp; IPv4&nbsp; TCP localhost:domain (LISTEN)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"comando-fuser-no-linux\">Comando fuser no Linux<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">O comando \u201c<a href=\"https:\/\/man.archlinux.org\/man\/fuser.1.pt_BR\" rel=\"nofollow noopener\" target=\"_blank\">fuser<\/a>\u201d tamb\u00e9m pode ser usado para mostrar informa\u00e7\u00f5es sobre uma determinada porta em aberto. Ele identifica os processos atrav\u00e9s dos arquivos ou sockets, retornando o PID dos processos:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo fuser 22\/tcp<br>22\/tcp:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;9857 24313 24400<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Para saber qual processo est\u00e1 usando determinado arquivo:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ fuser -v \/bin\/bash<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;USER&nbsp; &nbsp; &nbsp;PID ACCESS COMMAND<br>\/usr\/bin\/bash:&nbsp; &nbsp; &nbsp; &nbsp;ec2-user&nbsp; 16092 ...e. bash<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Os comandos&nbsp;<a href=\"https:\/\/www.ibm.com\/docs\/pt-br\/aix\/7.3?topic=command-using-netstat\" rel=\"nofollow noopener\" target=\"_blank\">netstat<\/a>,&nbsp;ss, lsof e <a href=\"https:\/\/man.archlinux.org\/man\/fuser.1.pt_BR\" rel=\"nofollow noopener\" target=\"_blank\">fuser <\/a>servem para ver as portas em aberto da m\u00e1quina local.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Existe uma ferramenta chamada&nbsp;<a href=\"https:\/\/pt.wikipedia.org\/wiki\/Nmap\" rel=\"nofollow noopener\" target=\"_blank\">nmap<\/a>&nbsp;que pode tamb\u00e9m descobrir as portas em aberto tanto da m\u00e1quina local, quanto de m\u00e1quinas remotas.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Inspe\u00e7\u00e3o de Portas Abertas Verificar portas abertas com o&nbsp;netstat, as op\u00e7\u00f5es \u201c-tunl\u201d podem ser usadas: Neste exemplo, o netstat lista as portas abertas TCP\/UDP: $ netstat -tunlActive Internet connections (only servers)Proto Local Address&nbsp; &nbsp;Foreign Addresstcp&nbsp; &nbsp; 127.0.0.53:53&nbsp; &nbsp;0.0.0.0:*&nbsp;tcp&nbsp; &nbsp; 0.0.0.0:22&nbsp; &nbsp; &nbsp; 0.0.0.0:*tcp6&nbsp; &nbsp;0 :::22&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:::*&nbsp;&nbsp;udp&nbsp; &nbsp; 127.0.0.53:53&nbsp; &nbsp;0.0.0.0:* O netstat [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4715,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAownujICw:productID":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[145],"tags":[],"class_list":["post-4706","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-rede"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/posts\/4706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/comments?post=4706"}],"version-history":[{"count":6,"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/posts\/4706\/revisions"}],"predecessor-version":[{"id":4717,"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/posts\/4706\/revisions\/4717"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/media\/4715"}],"wp:attachment":[{"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/media?parent=4706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/categories?post=4706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tpinformatica.com.br\/site\/wp-json\/wp\/v2\/tags?post=4706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}