Get a list of Open Ports in Linux












167















I need a Linux command to list all free open ports for use in an application



lsof -i TCP| fgrep LISTEN


Does not seen to be helping as the Ports it lists are not necessarily free for use. How do I list free open ports not in use?










share|improve this question















migrated from stackoverflow.com Jan 8 '13 at 11:29


This question came from our site for professional and enthusiast programmers.



















  • // , What if netstat is not available on the host?

    – Nathan Basanese
    Dec 14 '15 at 6:35
















167















I need a Linux command to list all free open ports for use in an application



lsof -i TCP| fgrep LISTEN


Does not seen to be helping as the Ports it lists are not necessarily free for use. How do I list free open ports not in use?










share|improve this question















migrated from stackoverflow.com Jan 8 '13 at 11:29


This question came from our site for professional and enthusiast programmers.



















  • // , What if netstat is not available on the host?

    – Nathan Basanese
    Dec 14 '15 at 6:35














167












167








167


95






I need a Linux command to list all free open ports for use in an application



lsof -i TCP| fgrep LISTEN


Does not seen to be helping as the Ports it lists are not necessarily free for use. How do I list free open ports not in use?










share|improve this question
















I need a Linux command to list all free open ports for use in an application



lsof -i TCP| fgrep LISTEN


Does not seen to be helping as the Ports it lists are not necessarily free for use. How do I list free open ports not in use?







linux ports






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 24 '14 at 20:32









Wilfred Hughes

18216




18216










asked Jan 8 '13 at 7:34









ErrorNotFoundExceptionErrorNotFoundException

941278




941278




migrated from stackoverflow.com Jan 8 '13 at 11:29


This question came from our site for professional and enthusiast programmers.









migrated from stackoverflow.com Jan 8 '13 at 11:29


This question came from our site for professional and enthusiast programmers.















  • // , What if netstat is not available on the host?

    – Nathan Basanese
    Dec 14 '15 at 6:35



















  • // , What if netstat is not available on the host?

    – Nathan Basanese
    Dec 14 '15 at 6:35

















// , What if netstat is not available on the host?

– Nathan Basanese
Dec 14 '15 at 6:35





// , What if netstat is not available on the host?

– Nathan Basanese
Dec 14 '15 at 6:35










7 Answers
7






active

oldest

votes


















234














netstat -lntu


as replied by @askmish will give you list of services running on your system on tcp and udp ports where





  • -l = only services which are listening on some port


  • -n = show port number, don't try to resolve the service name


  • -t = tcp ports


  • -u = udp ports


  • -p = name of the program


You don't need the 'p' parameter as you're only interested in getting which ports are free and not which program is running on it.



This only shows which ports on your system are used up, though. This doesn't tell you the status of your network e.g. if you're behind NAT and you want some services to be accessible from outside. Or if the firewall is blocking the port for outside visitors. In that case, nmap comes to the rescue.
WARNING: Use nmap only on networks which are under your control. Also, there are firewall rules which can block nmap pings, you'll have to fiddle around with options to get correct results.






share|improve this answer





















  • 13





    Note that netstat is deprecated on many systems and ss should be used instead.

    – Johu
    Apr 19 '17 at 21:44



















68














Since net-tools is deprecated, you can use the ss command instead of netstat if netstat is not present on your machine:



ss -lntu


should work similarly to



netstat -lntu


according to the built-in help:



-n, --numeric       don't resolve service names
-l, --listening display listening sockets
-t, --tcp display only TCP sockets
-u, --udp display only UDP sockets





share|improve this answer

































    20














    This command will list open network ports and the processes that own them:



    netstat -lnptu



    you can thereafter filter the results to your exact specs.



    You could also use nmap for more granular results about ports.






    share|improve this answer



















    • 1





      The -p flag requires root privileges for some processes, so it would be sudo netstat -lnptu

      – klaus se
      Oct 30 '14 at 1:17



















    4














    All opened ports including response traffic:



    netstat -tuwanp 2>/dev/null | awk '{print $4}' | sort | uniq -c | wc -l





    share|improve this answer





















    • 2





      A list of just unique port numbers and only IPv4: netstat -tuwanp4 | awk '{print $4}' | grep ':' | cut -d ":" -f 2 | sort | uniq

      – Aaron C. de Bruyn
      Oct 9 '15 at 20:13













    • +1 for showing how to filter and extract the numbers from the result. Edited to remove stderr output from netstat (which adds a header to the result in Ubuntu).

      – datashaman
      Apr 4 '16 at 6:17











    • Hmm, on second thoughts. -1 for not answering the question.

      – datashaman
      Apr 4 '16 at 6:18



















    0














    The following command will work on any Unix which outputs in the same format as Ubuntu / Debian - where the local address is in the column 4 and the output includes a 2 line header at the top. If either of those numbers is different, tweak the awk command below.



    If you want IPv4 only:



    netstat -lnt | awk 'NR>2{print $4}' | grep -E '0.0.0.0:' | sed 's/.*://' | sort -n | uniq


    If you want IPv6 only:



    netstat -lnt | awk 'NR>2{print $4}' | grep -E ':::' | sed 's/.*://' | sort -n | uniq


    If you want both together:



    netstat -lnt | awk 'NR>2{print $4}' | grep -E '(0.0.0.0:|:::)' | sed 's/.*://' | sort -n | uniq


    The command outputs a list of port numbers that are listening on all interfaces. If you want to list all ports that are listening on localhost interface, then use something like this:



    netstat -lnt | awk 'NR>2{print $4}' | grep -E '(127.0.0.1:|::1:)' | sed 's/.*://' | sort -n | uniq





    share|improve this answer































      0














      Try



      sudo netstat -plnt | grep -E '(0.0.0.0:|:::|127.0.0.1:|::1:)' |  awk 'NR>2{print $7}' | sort -n  | uniq


      and look at this.






      share|improve this answer

































        0














        My take on the original question was that he was asking about the unused ports, not the ports currently connected to services. If this is the case, there's no specific way to list them, other than to listed the used ports and assume the others are unused.



        One additional point to keep in mind: as a user, you'll not be able to open a port less than 1024 (you'll need root permissions for that).






        share|improve this answer























          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f529830%2fget-a-list-of-open-ports-in-linux%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          7 Answers
          7






          active

          oldest

          votes








          7 Answers
          7






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          234














          netstat -lntu


          as replied by @askmish will give you list of services running on your system on tcp and udp ports where





          • -l = only services which are listening on some port


          • -n = show port number, don't try to resolve the service name


          • -t = tcp ports


          • -u = udp ports


          • -p = name of the program


          You don't need the 'p' parameter as you're only interested in getting which ports are free and not which program is running on it.



          This only shows which ports on your system are used up, though. This doesn't tell you the status of your network e.g. if you're behind NAT and you want some services to be accessible from outside. Or if the firewall is blocking the port for outside visitors. In that case, nmap comes to the rescue.
          WARNING: Use nmap only on networks which are under your control. Also, there are firewall rules which can block nmap pings, you'll have to fiddle around with options to get correct results.






          share|improve this answer





















          • 13





            Note that netstat is deprecated on many systems and ss should be used instead.

            – Johu
            Apr 19 '17 at 21:44
















          234














          netstat -lntu


          as replied by @askmish will give you list of services running on your system on tcp and udp ports where





          • -l = only services which are listening on some port


          • -n = show port number, don't try to resolve the service name


          • -t = tcp ports


          • -u = udp ports


          • -p = name of the program


          You don't need the 'p' parameter as you're only interested in getting which ports are free and not which program is running on it.



          This only shows which ports on your system are used up, though. This doesn't tell you the status of your network e.g. if you're behind NAT and you want some services to be accessible from outside. Or if the firewall is blocking the port for outside visitors. In that case, nmap comes to the rescue.
          WARNING: Use nmap only on networks which are under your control. Also, there are firewall rules which can block nmap pings, you'll have to fiddle around with options to get correct results.






          share|improve this answer





















          • 13





            Note that netstat is deprecated on many systems and ss should be used instead.

            – Johu
            Apr 19 '17 at 21:44














          234












          234








          234







          netstat -lntu


          as replied by @askmish will give you list of services running on your system on tcp and udp ports where





          • -l = only services which are listening on some port


          • -n = show port number, don't try to resolve the service name


          • -t = tcp ports


          • -u = udp ports


          • -p = name of the program


          You don't need the 'p' parameter as you're only interested in getting which ports are free and not which program is running on it.



          This only shows which ports on your system are used up, though. This doesn't tell you the status of your network e.g. if you're behind NAT and you want some services to be accessible from outside. Or if the firewall is blocking the port for outside visitors. In that case, nmap comes to the rescue.
          WARNING: Use nmap only on networks which are under your control. Also, there are firewall rules which can block nmap pings, you'll have to fiddle around with options to get correct results.






          share|improve this answer















          netstat -lntu


          as replied by @askmish will give you list of services running on your system on tcp and udp ports where





          • -l = only services which are listening on some port


          • -n = show port number, don't try to resolve the service name


          • -t = tcp ports


          • -u = udp ports


          • -p = name of the program


          You don't need the 'p' parameter as you're only interested in getting which ports are free and not which program is running on it.



          This only shows which ports on your system are used up, though. This doesn't tell you the status of your network e.g. if you're behind NAT and you want some services to be accessible from outside. Or if the firewall is blocking the port for outside visitors. In that case, nmap comes to the rescue.
          WARNING: Use nmap only on networks which are under your control. Also, there are firewall rules which can block nmap pings, you'll have to fiddle around with options to get correct results.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 24 '13 at 15:06









          Bojangles

          3651718




          3651718










          answered Jan 8 '13 at 11:51









          mehulvedmehulved

          2,471183




          2,471183








          • 13





            Note that netstat is deprecated on many systems and ss should be used instead.

            – Johu
            Apr 19 '17 at 21:44














          • 13





            Note that netstat is deprecated on many systems and ss should be used instead.

            – Johu
            Apr 19 '17 at 21:44








          13




          13





          Note that netstat is deprecated on many systems and ss should be used instead.

          – Johu
          Apr 19 '17 at 21:44





          Note that netstat is deprecated on many systems and ss should be used instead.

          – Johu
          Apr 19 '17 at 21:44













          68














          Since net-tools is deprecated, you can use the ss command instead of netstat if netstat is not present on your machine:



          ss -lntu


          should work similarly to



          netstat -lntu


          according to the built-in help:



          -n, --numeric       don't resolve service names
          -l, --listening display listening sockets
          -t, --tcp display only TCP sockets
          -u, --udp display only UDP sockets





          share|improve this answer






























            68














            Since net-tools is deprecated, you can use the ss command instead of netstat if netstat is not present on your machine:



            ss -lntu


            should work similarly to



            netstat -lntu


            according to the built-in help:



            -n, --numeric       don't resolve service names
            -l, --listening display listening sockets
            -t, --tcp display only TCP sockets
            -u, --udp display only UDP sockets





            share|improve this answer




























              68












              68








              68







              Since net-tools is deprecated, you can use the ss command instead of netstat if netstat is not present on your machine:



              ss -lntu


              should work similarly to



              netstat -lntu


              according to the built-in help:



              -n, --numeric       don't resolve service names
              -l, --listening display listening sockets
              -t, --tcp display only TCP sockets
              -u, --udp display only UDP sockets





              share|improve this answer















              Since net-tools is deprecated, you can use the ss command instead of netstat if netstat is not present on your machine:



              ss -lntu


              should work similarly to



              netstat -lntu


              according to the built-in help:



              -n, --numeric       don't resolve service names
              -l, --listening display listening sockets
              -t, --tcp display only TCP sockets
              -u, --udp display only UDP sockets






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 20 '18 at 10:28









              Suzana

              15611




              15611










              answered Jun 8 '16 at 20:19









              Eric FinnEric Finn

              79868




              79868























                  20














                  This command will list open network ports and the processes that own them:



                  netstat -lnptu



                  you can thereafter filter the results to your exact specs.



                  You could also use nmap for more granular results about ports.






                  share|improve this answer



















                  • 1





                    The -p flag requires root privileges for some processes, so it would be sudo netstat -lnptu

                    – klaus se
                    Oct 30 '14 at 1:17
















                  20














                  This command will list open network ports and the processes that own them:



                  netstat -lnptu



                  you can thereafter filter the results to your exact specs.



                  You could also use nmap for more granular results about ports.






                  share|improve this answer



















                  • 1





                    The -p flag requires root privileges for some processes, so it would be sudo netstat -lnptu

                    – klaus se
                    Oct 30 '14 at 1:17














                  20












                  20








                  20







                  This command will list open network ports and the processes that own them:



                  netstat -lnptu



                  you can thereafter filter the results to your exact specs.



                  You could also use nmap for more granular results about ports.






                  share|improve this answer













                  This command will list open network ports and the processes that own them:



                  netstat -lnptu



                  you can thereafter filter the results to your exact specs.



                  You could also use nmap for more granular results about ports.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 8 '13 at 7:45









                  askmishaskmish

                  301126




                  301126








                  • 1





                    The -p flag requires root privileges for some processes, so it would be sudo netstat -lnptu

                    – klaus se
                    Oct 30 '14 at 1:17














                  • 1





                    The -p flag requires root privileges for some processes, so it would be sudo netstat -lnptu

                    – klaus se
                    Oct 30 '14 at 1:17








                  1




                  1





                  The -p flag requires root privileges for some processes, so it would be sudo netstat -lnptu

                  – klaus se
                  Oct 30 '14 at 1:17





                  The -p flag requires root privileges for some processes, so it would be sudo netstat -lnptu

                  – klaus se
                  Oct 30 '14 at 1:17











                  4














                  All opened ports including response traffic:



                  netstat -tuwanp 2>/dev/null | awk '{print $4}' | sort | uniq -c | wc -l





                  share|improve this answer





















                  • 2





                    A list of just unique port numbers and only IPv4: netstat -tuwanp4 | awk '{print $4}' | grep ':' | cut -d ":" -f 2 | sort | uniq

                    – Aaron C. de Bruyn
                    Oct 9 '15 at 20:13













                  • +1 for showing how to filter and extract the numbers from the result. Edited to remove stderr output from netstat (which adds a header to the result in Ubuntu).

                    – datashaman
                    Apr 4 '16 at 6:17











                  • Hmm, on second thoughts. -1 for not answering the question.

                    – datashaman
                    Apr 4 '16 at 6:18
















                  4














                  All opened ports including response traffic:



                  netstat -tuwanp 2>/dev/null | awk '{print $4}' | sort | uniq -c | wc -l





                  share|improve this answer





















                  • 2





                    A list of just unique port numbers and only IPv4: netstat -tuwanp4 | awk '{print $4}' | grep ':' | cut -d ":" -f 2 | sort | uniq

                    – Aaron C. de Bruyn
                    Oct 9 '15 at 20:13













                  • +1 for showing how to filter and extract the numbers from the result. Edited to remove stderr output from netstat (which adds a header to the result in Ubuntu).

                    – datashaman
                    Apr 4 '16 at 6:17











                  • Hmm, on second thoughts. -1 for not answering the question.

                    – datashaman
                    Apr 4 '16 at 6:18














                  4












                  4








                  4







                  All opened ports including response traffic:



                  netstat -tuwanp 2>/dev/null | awk '{print $4}' | sort | uniq -c | wc -l





                  share|improve this answer















                  All opened ports including response traffic:



                  netstat -tuwanp 2>/dev/null | awk '{print $4}' | sort | uniq -c | wc -l






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 4 '16 at 8:44









                  datashaman

                  1055




                  1055










                  answered Nov 3 '14 at 4:33









                  diyismdiyism

                  135112




                  135112








                  • 2





                    A list of just unique port numbers and only IPv4: netstat -tuwanp4 | awk '{print $4}' | grep ':' | cut -d ":" -f 2 | sort | uniq

                    – Aaron C. de Bruyn
                    Oct 9 '15 at 20:13













                  • +1 for showing how to filter and extract the numbers from the result. Edited to remove stderr output from netstat (which adds a header to the result in Ubuntu).

                    – datashaman
                    Apr 4 '16 at 6:17











                  • Hmm, on second thoughts. -1 for not answering the question.

                    – datashaman
                    Apr 4 '16 at 6:18














                  • 2





                    A list of just unique port numbers and only IPv4: netstat -tuwanp4 | awk '{print $4}' | grep ':' | cut -d ":" -f 2 | sort | uniq

                    – Aaron C. de Bruyn
                    Oct 9 '15 at 20:13













                  • +1 for showing how to filter and extract the numbers from the result. Edited to remove stderr output from netstat (which adds a header to the result in Ubuntu).

                    – datashaman
                    Apr 4 '16 at 6:17











                  • Hmm, on second thoughts. -1 for not answering the question.

                    – datashaman
                    Apr 4 '16 at 6:18








                  2




                  2





                  A list of just unique port numbers and only IPv4: netstat -tuwanp4 | awk '{print $4}' | grep ':' | cut -d ":" -f 2 | sort | uniq

                  – Aaron C. de Bruyn
                  Oct 9 '15 at 20:13







                  A list of just unique port numbers and only IPv4: netstat -tuwanp4 | awk '{print $4}' | grep ':' | cut -d ":" -f 2 | sort | uniq

                  – Aaron C. de Bruyn
                  Oct 9 '15 at 20:13















                  +1 for showing how to filter and extract the numbers from the result. Edited to remove stderr output from netstat (which adds a header to the result in Ubuntu).

                  – datashaman
                  Apr 4 '16 at 6:17





                  +1 for showing how to filter and extract the numbers from the result. Edited to remove stderr output from netstat (which adds a header to the result in Ubuntu).

                  – datashaman
                  Apr 4 '16 at 6:17













                  Hmm, on second thoughts. -1 for not answering the question.

                  – datashaman
                  Apr 4 '16 at 6:18





                  Hmm, on second thoughts. -1 for not answering the question.

                  – datashaman
                  Apr 4 '16 at 6:18











                  0














                  The following command will work on any Unix which outputs in the same format as Ubuntu / Debian - where the local address is in the column 4 and the output includes a 2 line header at the top. If either of those numbers is different, tweak the awk command below.



                  If you want IPv4 only:



                  netstat -lnt | awk 'NR>2{print $4}' | grep -E '0.0.0.0:' | sed 's/.*://' | sort -n | uniq


                  If you want IPv6 only:



                  netstat -lnt | awk 'NR>2{print $4}' | grep -E ':::' | sed 's/.*://' | sort -n | uniq


                  If you want both together:



                  netstat -lnt | awk 'NR>2{print $4}' | grep -E '(0.0.0.0:|:::)' | sed 's/.*://' | sort -n | uniq


                  The command outputs a list of port numbers that are listening on all interfaces. If you want to list all ports that are listening on localhost interface, then use something like this:



                  netstat -lnt | awk 'NR>2{print $4}' | grep -E '(127.0.0.1:|::1:)' | sed 's/.*://' | sort -n | uniq





                  share|improve this answer




























                    0














                    The following command will work on any Unix which outputs in the same format as Ubuntu / Debian - where the local address is in the column 4 and the output includes a 2 line header at the top. If either of those numbers is different, tweak the awk command below.



                    If you want IPv4 only:



                    netstat -lnt | awk 'NR>2{print $4}' | grep -E '0.0.0.0:' | sed 's/.*://' | sort -n | uniq


                    If you want IPv6 only:



                    netstat -lnt | awk 'NR>2{print $4}' | grep -E ':::' | sed 's/.*://' | sort -n | uniq


                    If you want both together:



                    netstat -lnt | awk 'NR>2{print $4}' | grep -E '(0.0.0.0:|:::)' | sed 's/.*://' | sort -n | uniq


                    The command outputs a list of port numbers that are listening on all interfaces. If you want to list all ports that are listening on localhost interface, then use something like this:



                    netstat -lnt | awk 'NR>2{print $4}' | grep -E '(127.0.0.1:|::1:)' | sed 's/.*://' | sort -n | uniq





                    share|improve this answer


























                      0












                      0








                      0







                      The following command will work on any Unix which outputs in the same format as Ubuntu / Debian - where the local address is in the column 4 and the output includes a 2 line header at the top. If either of those numbers is different, tweak the awk command below.



                      If you want IPv4 only:



                      netstat -lnt | awk 'NR>2{print $4}' | grep -E '0.0.0.0:' | sed 's/.*://' | sort -n | uniq


                      If you want IPv6 only:



                      netstat -lnt | awk 'NR>2{print $4}' | grep -E ':::' | sed 's/.*://' | sort -n | uniq


                      If you want both together:



                      netstat -lnt | awk 'NR>2{print $4}' | grep -E '(0.0.0.0:|:::)' | sed 's/.*://' | sort -n | uniq


                      The command outputs a list of port numbers that are listening on all interfaces. If you want to list all ports that are listening on localhost interface, then use something like this:



                      netstat -lnt | awk 'NR>2{print $4}' | grep -E '(127.0.0.1:|::1:)' | sed 's/.*://' | sort -n | uniq





                      share|improve this answer













                      The following command will work on any Unix which outputs in the same format as Ubuntu / Debian - where the local address is in the column 4 and the output includes a 2 line header at the top. If either of those numbers is different, tweak the awk command below.



                      If you want IPv4 only:



                      netstat -lnt | awk 'NR>2{print $4}' | grep -E '0.0.0.0:' | sed 's/.*://' | sort -n | uniq


                      If you want IPv6 only:



                      netstat -lnt | awk 'NR>2{print $4}' | grep -E ':::' | sed 's/.*://' | sort -n | uniq


                      If you want both together:



                      netstat -lnt | awk 'NR>2{print $4}' | grep -E '(0.0.0.0:|:::)' | sed 's/.*://' | sort -n | uniq


                      The command outputs a list of port numbers that are listening on all interfaces. If you want to list all ports that are listening on localhost interface, then use something like this:



                      netstat -lnt | awk 'NR>2{print $4}' | grep -E '(127.0.0.1:|::1:)' | sed 's/.*://' | sort -n | uniq






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Apr 4 '16 at 6:29









                      datashamandatashaman

                      1055




                      1055























                          0














                          Try



                          sudo netstat -plnt | grep -E '(0.0.0.0:|:::|127.0.0.1:|::1:)' |  awk 'NR>2{print $7}' | sort -n  | uniq


                          and look at this.






                          share|improve this answer






























                            0














                            Try



                            sudo netstat -plnt | grep -E '(0.0.0.0:|:::|127.0.0.1:|::1:)' |  awk 'NR>2{print $7}' | sort -n  | uniq


                            and look at this.






                            share|improve this answer




























                              0












                              0








                              0







                              Try



                              sudo netstat -plnt | grep -E '(0.0.0.0:|:::|127.0.0.1:|::1:)' |  awk 'NR>2{print $7}' | sort -n  | uniq


                              and look at this.






                              share|improve this answer















                              Try



                              sudo netstat -plnt | grep -E '(0.0.0.0:|:::|127.0.0.1:|::1:)' |  awk 'NR>2{print $7}' | sort -n  | uniq


                              and look at this.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jan 16 at 22:33









                              zx485

                              935713




                              935713










                              answered Jan 16 at 19:51









                              RobokishanRobokishan

                              92




                              92























                                  0














                                  My take on the original question was that he was asking about the unused ports, not the ports currently connected to services. If this is the case, there's no specific way to list them, other than to listed the used ports and assume the others are unused.



                                  One additional point to keep in mind: as a user, you'll not be able to open a port less than 1024 (you'll need root permissions for that).






                                  share|improve this answer




























                                    0














                                    My take on the original question was that he was asking about the unused ports, not the ports currently connected to services. If this is the case, there's no specific way to list them, other than to listed the used ports and assume the others are unused.



                                    One additional point to keep in mind: as a user, you'll not be able to open a port less than 1024 (you'll need root permissions for that).






                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      My take on the original question was that he was asking about the unused ports, not the ports currently connected to services. If this is the case, there's no specific way to list them, other than to listed the used ports and assume the others are unused.



                                      One additional point to keep in mind: as a user, you'll not be able to open a port less than 1024 (you'll need root permissions for that).






                                      share|improve this answer













                                      My take on the original question was that he was asking about the unused ports, not the ports currently connected to services. If this is the case, there's no specific way to list them, other than to listed the used ports and assume the others are unused.



                                      One additional point to keep in mind: as a user, you'll not be able to open a port less than 1024 (you'll need root permissions for that).







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jan 16 at 23:21









                                      joatjoat

                                      45629




                                      45629






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Super User!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f529830%2fget-a-list-of-open-ports-in-linux%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          How do I know what Microsoft account the skydrive app is syncing to?

                                          When does type information flow backwards in C++?

                                          Grease: Live!