Which command Linux can use to view a service and its ports, process numbers

Source: Internet
Author: User

  1. Netstat/lsof
  2. The netstat command is used to display statistics related to IP, TCP, UDP, and ICMP protocols, and is typically used to verify network connectivity across ports on the local computer.
  3. -a displays a list of all valid connection information (including established connections, including those that listen for connection requests)
  4. -N Shows all valid connections established
  5. -T TCP protocol
  6. -U UDP protocol
  7. -L Query the program being monitored
  8. -P shows the program identification code and program name using the socket
  9. Example: Netstat-ntupl|grep processname
  10. How do I query only tomcat connections?
  11. Netstat-na|grep estab |grep |wc-l
  12. Netstat-na|grep estab |grep 8080 |wc-l
  13. Common Port Description:
  14. Port: 21
  15. Service: FTP server open port for uploading, downloading.
  16. Port: 22
  17. Service: SSH
  18. PORT: 80
  19. Service: HTTP for web browsing
  20. PORT: 389
  21. Services: LDAP ILS Lightweight Directory Access Protocol and netmeetinginternet Locator Server
  22. Port: 443
  23. Service: A Web browsing port can provide encryption and another HTTP transmission over a secure port
  24. Port: 8080
  25. Service: Proxy port
  26. Open the terminal and execute the following command to see the port status of each process:
  27. # ps-ef|wc-l //view total number of processes running in the background
  28. # Ps-fu CSVN //view CSVN process
  29. # NETSTAT-LNTP //See which ports are open
  30. # Netstat-r //This option can display information about the routing table
  31. # netstat-a //This option displays a list of all valid connection information
  32. # netstat-an|grep 8080
  33. # Netstat-na|grep-i Listen //Can see the current system listening port number
  34. # Netstat-antup //View the established connection process, the occupied port.
  35. netstat-anp|grep1487
  36. lsof-i:1487
  37. See which processes open the specified port 1487
  38. The shutdown port is actually shutting down its corresponding service, such as 80 port is httpd shutdown 80 port can be implemented by shutting down the httpd service
  39. Each port has a daemon, kill the daemon.
  40. The host's port is divided into a listening port and a randomly available premium port
  41. Listening Port: The listening port is the service that the host is powered on, and this service enables a port on the Linux system to listen for client requests
  42. A randomly available premium port:
  43. Linux to request a service from a host, the Linux host needs to enable a port to connect externally Linux randomly connects to a port that is not in use and has a number greater than 1024
  44. Only the root user can open port 1-1024 to indicate root privileges
  45. Netstat-n Show Connection Status
  46. NETSTAT-TL displays the name of the service that is currently listening
  47. Linux is a tool to list the open files of the current system, and in the Linux environment, everything is in the form of files.
  48. Lsof output information to display system open files by default show all files open by all processes
  49. lsof filename Displays all processes that open the specified file
  50. Lsof-c string Displays all open files for the process containing the specified characters in the command column
  51. Lsof-u Username Displays the files that are open by the user process
  52. Lsof-g GID shows the process of attribution to GID
  53. Lsof-i Show eligible process conditions
  54. Lsof-d the process that displays the specified file descriptor
  55. Lsof-a indicates that two parameters must be met before the results are displayed
  56. Example: lsof-i:1487
  57. To view files whose file type is txt opened by the root user process:
  58. Lsof-a-u root-d txt
  59. Lsof Use Instances
  60. 1. Find using the file system
  61. When uninstalling the file system, an error occurs if there are any open files in the file system. Lsof can be used to find out which processes are using the currently uninstalled file system
  62. # lsof/gtes11/
  63. COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
  64. Bash 4208 root cwd DIR 3,1 40962/gtes11/
  65. Vim 4230 root CWD DIR 3,1 40962/gtes11/
  66. 2. Recover deleted files
  67. When a Linux computer is compromised, it is common for log files to be deleted and administrative errors to cause accidental deletion of important files.
  68. When a process opens a file, it remains on disk as long as the process remains open for that file, even if it is deleted. This means that the process does not know that the file has been deleted, and in the/proc directory, it contains various files that reflect the kernel and the process tree.
  69. When a file in the system is accidentally deleted, as long as there are processes in the system that are accessing the file, you can recover the file from the/proc directory by lsof
  70. Use lsof to see if there are currently processes open/var/logmessages files
  71. # lsof |grep/var/log/messages syslogd 1283 root 2w REG 3,3 5381017 1773647/var/log/messages (deleted) from/proc/128 3/FD/2
  72. This method of recovering deleted files is useful for many applications, especially log files and databases

Which command Linux can use to view a service and its ports, process numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.