• หน้าแรก
  • หลักสูตร
  • บทความ
  • ร้านค้า
  • ติดต่อเรา
    มีคำถามเกี่ยวกับ odoo ?
    (02) 4302475
    info@odoothaidev.com
    Login
    Odoothaidev - We are Odoo professional in Thailand
    • หน้าแรก
    • หลักสูตร
    • บทความ
    • ร้านค้า
    • ติดต่อเรา

      Linux

      • บ้าน
      • บล็อก
      • Linux
      • How to check if port is in use on Linux or Unix

      How to check if port is in use on Linux or Unix

      • โพสโดย alex
      • หมวดหมู่ Linux, Ubuntu
      • วันที่ พฤศจิกายน 22, 2022

      How do I determine if a port is in use under Linux or Unix-like system? How can I verify which ports are listening on Linux server? How do I check if port is in use on Linux operating system using the CLI?

      It is important you verify which ports are listening on the server’s network interfaces. You need to pay attention to open ports to detect an intrusion. Apart from an intrusion, for troubleshooting purposes, it may be necessary to check if a port is already in use by a different application on your servers. For example, you may install Apache and Nginx server on the same system. So it is necessary to know if Apache or Nginx is using TCP port # 80/443. This quick tutorial provides steps to use the netstat, nmap and lsof command to check the ports in use and view the application that is utilizing the port.

      How to check if port is in use in

      To check the listening ports and applications on Linux:

      1. Open a terminal application i.e. shell prompt.
      2. Run any one of the following command on Linux to see open ports:
        $ sudo lsof -i -P -n | grep LISTEN
        $ sudo netstat -tulpn | grep LISTEN
        $ sudo ss -tulpn | grep LISTEN
        $ sudo lsof -i:22 ## see a specific port such as 22 ##
        $ sudo nmap -sTU -O IP-address-Here
      3. For the latest version of Linux use the ss command. For example, ss -tulw

      Let us see commands and its output in details.

      Option #1: lsof command

      The syntax is:
      $ sudo lsof -i -P -n
      $ sudo lsof -i -P -n | grep LISTEN
      $ doas lsof -i -P -n | grep LISTEN # OpenBSD #

      Sample outputs:

      Fig.01: Check the listening ports and applications with lsof command

      Fig.01: Check the listening ports and applications with lsof command

      Consider the last line from above outputs:

       

      sshd    85379     root    3u  IPv4 0xffff80000039e000      0t0  TCP 10.86.128.138:22 (LISTEN)
      • sshd is the name of the application.
      • 10.86.128.138 is the IP address to which sshd application bind to (LISTEN)
      • 22 is the TCP port that is being used (LISTEN)
      • 85379 is the process ID of the sshd process

      Viewing the Internet network services list

      The /etc/services is a text file mapping between human-friendly textual names for internet services and their underlying assigned port numbers and protocol types. Use the cat command or more command/less command to view it:
      $ less /etc/services
      A sample file:

      tcpmux          1/tcp                           # TCP port service multiplexer
      echo            7/tcp
      echo            7/udp
      discard         9/tcp           sink null
      discard         9/udp           sink null
      systat          11/tcp          users
      daytime         13/tcp
      daytime         13/udp
      netstat         15/tcp
      qotd            17/tcp          quote
      chargen         19/tcp          ttytst source
      chargen         19/udp          ttytst source
      ftp-data        20/tcp
      ftp             21/tcp
      fsp             21/udp          fspd
      ssh             22/tcp                          # SSH Remote Login Protocol
      telnet          23/tcp
      smtp            25/tcp          mail
      time            37/tcp          timserver
      time            37/udp          timserver
      whois           43/tcp          nicname
      tacacs          49/tcp                          # Login Host Protocol (TACACS)
      tacacs          49/udp
      domain          53/tcp                          # Domain Name Server
      domain          53/udp
      
      

      Each line describes one service, and is of the form:

      #service-name   port/protocol   [aliases ...]
      ssh             22/tcp                          # SSH Remote Login Protocol
      time            37/tcp          timserver

      Option #2: netstat or ss command

      You can check the listening ports and applications with netstat as follows.

      Linux netstat syntax

      Run netstat command along with grep command to filter out port in LISTEN state:
      $ netstat -tulpn | grep LISTEN
      The netstat command deprecated for some time on Linux. Therefore, you need to use the ss command as follows:
      $ sudo ss -tulw
      $ sudo ss -tulwn
      $ sudo ss -tulwn | grep LISTEN

      Linux check if port is in use using ss command
      Where, ss command options are as follows:

      • -t : Show only TCP sockets on Linux
      • -u : Display only UDP sockets on Linux
      • -l : Show listening sockets. For example, TCP port 22 is opened by SSHD server.
      • -p : List process name that opened sockets
      • -n : Don’t resolve service names i.e. don’t use DNS

      Related: Linux Find Out Which Process Is Listening Upon a Port

      FreeBSD/macOS (OS X) netstat syntax

      The syntax is as follows:
      $ netstat -anp tcp | grep LISTEN
      $ netstat -anp udp | grep LISTEN

      OpenBSD netstat syntax

      $ netstat -na -f inet | grep LISTEN
      $ netstat -nat | grep LISTEN

      Option #3: nmap command

      The syntax is:
      $ sudo nmap -sT -O localhost
      $ sudo nmap -sU -O 192.168.2.13 ##[ list open UDP ports ]##
      $ sudo nmap -sT -O 192.168.2.13 ##[ list open TCP ports ]##

      Sample outputs:

      Fig.02: Determines which ports are listening for TCP connections using nmap

      Fig.02: Determines which ports are listening for TCP connections using nmap

      You can combine TCP/UDP scan in a single command:
      $ sudo nmap -sTU -O 192.168.2.13

       

      A note about Windows users

      You can check port usage from Windows operating system using following command:
      $ netstat -bano | more
      $ netstat -bano | grep LISTENING
      $ netstat -bano | findstr /R /C:"[LISTEING]"

      Conclusion

      This page explained command to determining if a port is in use on Linux or Unix-like server. For more information see the nmap command and lsof command page online here or by typing the man command as follows:
      $ man lsof
      $ man ss
      $ man netstat
      $ man nmap
      $ man 5 services

      • Share:
      อวตารของผู้เขียน
      alex

      โพสต์ก่อนหน้า

      Odoo 14.0 จากการเปลี่ยนแปลงในรายงาน
      พฤศจิกายน 22, 2022

      โพสต์ถัดไป

      Installing Odoo (enterprise) on Ubuntu
      พฤศจิกายน 22, 2022

      คุณอาจชอบ

      3 Ways to Find Out Which Process Listening on a Particular Port
      24 สิงหาคม, 2021

      A port is a logical entity which represe …

      01-Ubuntu-Web-Site-1024×767[1]
      รีวิวการติดตั้ง Ubuntu 16.04 Server
      15 กรกฎาคม, 2019

      ค้นหาบทความ

      หมวดหมู่

      หมวดหมู่

      • Accounting
      • Adobe XD
      • API
      • Blog
      • Business
      • Buttons
      • CRM
      • Custom Fields
      • Design / Branding
      • Django
      • Ecommerce
      • ERP
      • ERP Flow
      • Express
      • Flectra
      • Form View
      • Frontend
      • Github
      • Github
      • Grant Chart
      • Header
      • iReport
      • Jasper Server & Server
      • Jaspersoft Studio
      • Java
      • JSON-RPC
      • Lazada
      • Linux
      • MLM
      • MRP
      • Nignx Proxy
      • NodeJS
      • Odoo 10
      • Odoo 12 Module
      • Odoo 13
      • Odoo 14 Development
      • Odoo 16
      • Odoo 8
      • Odoo 9
      • Odoo API
      • Odoo Certification
      • Odoo Developer
      • Odoo Ebook
      • Odoo Enterprise
      • Odoo ERP
      • Odoo Event
      • Odoo Implement
      • Odoo Inventory
      • Odoo Report
      • Odoo V15
      • Open Source
      • Open-office
      • OpenERP 7.0
      • PhantomJS
      • Postgres SQL
      • Programming Language
      • Project Management
      • Python
      • Python3
      • Qweb
      • Reporting ระบบรายงาน
      • RML Report
      • Search View and Filters
      • Social Network
      • Statusbar
      • Ubuntu
      • Uncategorized
      • Voip & Call Center
      • Warehouse Management
      • WMS
      • Woocommerce
      • Workflow
      • XML-RPC
      • การ Implement
      • การเก็บข้อมูล Pre-Requirement
      • การเตรียมตัวเพื่อใช้งาน erp
      • ความรู้ด้านการตลาด CRM
      • ธีมเว็บไซต์ Odoo
      • ธุรกิจบริการ
      • ธุรกิจประเภทจัดอบรมสัมมนา
      • ธุรกิจสิ่งพิมพ์
      • นักพัฒนา
      • ประเภทธุรกิจที่เหมาะกับ Odoo
      • ระบบบัญชี
      • ระบบเคลม
      • ลิขสิทธิ์ – License
      Introduction LearnPress – LMS plugin

      Introduction LearnPress – LMS plugin

      Free
      From Zero to Hero with Nodejs

      From Zero to Hero with Nodejs

      Free
      Learn Python – Interactive Python

      Learn Python – Interactive Python

      $69.00

      บทความล่าสุด

      V16 Planned Date of Tasks are invisible.
      12ก.พ.2023
      Odoo Implement Methodology
      29พ.ย.2022
      Odoo Enterprise Subscription Agreement
      29พ.ย.2022
      (02) 430-2475
      info@odoothaidev.com
      Facebook Twitter Google-plus Pinterest

      Odoothaidev by OdooTeaM.

      • Privacy
      • Terms
      • Sitemap
      • Purchase

      เข้าสู่ระบบด้วยบัญชีเว็บไซต์ของคุณ

      ลืมรหัสผ่าน?

      Click to Copy