How Linux looks at what process the port is using, using the tool Lsof,netstat:
1.lsof-i: Port number
The lsof command is used to view the files that your process is opening, the process that opened the file, the ports that the process opened (TCP, UDP). Retrieve/Recover deleted files. is a very convenient system monitoring tool, because the lsof command requires access to core memory and various files, so the root user needs to execute.
If the system does not have lsof tools, it can be installed via Yum.
Yum Install lsof
Options:
-A: Lists the processes that open files exist;: Lists the files opened by the specified process;-G: List the GID process details;-d< file number;: Lists the processes that occupy the file number, +d< directory;: Lists the files that are open in the directory; +d < directory: Recursively lists the files opened in the directory,-n< directory;: Lists files using NFS,-i< conditions;: Lists the eligible processes. (4, 6, protocol,: Port, @ip)-p< process number;: Lists the files opened by the specified process number;-U: Lists the UID number process details;-H: Displays the Help information;-V: Displays the version information.
Example: vm_170_176_sles10_64:~ # lsof-i:3306 COMMAND PID USER FD TYPE DEVICE SIZE NODE namemysqld 5103 root 13u IPv4 28776382 TCP *:mysql (LISTEN)
2. NETSTAT-TUNLP | grep Port number
The netstat command is used to print the status information of network systems in Linux, allowing you to learn about the network conditions of the entire Linux system.
options:
-a or--all: Shows the type of socket; -a< network in all lines > or--< network type > : Lists the relevant addresses in the network type connection; -c or--continuous: Network status is continuously listed, -c or--cache: Displays the cache information for the router configuration, -e or--extend: Displays other relevant information about the network; -f or--fib: Displays Fib; -g or--groups: Displays the multicast feature Group Members list, -h or--help: online help; -i or--interfaces: Displays the Web interface information form; -l or--listening: Displays the Socket; -m or--masquerade of the server in the monitor: Displays the spoofed network connection, -n or--numeric: Use the IP address directly instead of the domain name server; -n or--netlink or--symbolic: Displays the symbolic connection name of the network hardware peripheral device, -o or--timers: Display timer; - P or--programs: shows the program identification code and program name of the socket being used; -r or--route: Display routing table; -s or--statistice: Display the statistics of network work; -t or--tcp: Displays the connection status of the TCP transport protocol, -u or--UDP: Displays the connection status of the UDP transport protocol, &NBSP;-V or--verbose: Displays the instruction execution process; - V or--version: Displays version information, -w or--raw: Displays the connection status of the raw transport protocol, -x or--unix: The effect of this parameter is the same as specifying the "-a unix" parameter; -- IP or--inet: The effect of this parameter is the same as specifying the "-a inet" parameter.
Example: vm_170_176_sles10_64:~ # NETSTAT-TUNLP | grep 3306tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 5103/mysqld
Linux to see which program is consuming the port