linux port query command

Any knowledge is use it or lose it. I haven't touched linux for a while, and all the knowledge points in my brain seem to have disappeared, so I am speechless. Simply, write another record, strengthen your memory, and read your own information next time you need it.

lsof command

The Linux port query command can be implemented through lsof:

  1. lsof : short for List Open Files, which can list the file information opened by various processes, as shown in the following figure:

Directly use the lsof command to get all the current information, there will be a lot, so generally you can get more accurate information by combining parameters, the specific parameters of the command, we can use the --help command to query:

[root@localhost 桌面]# lsof --help
lsof: illegal option character: -
lsof: -e not followed by a file system path: "lp"
lsof 4.91
 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
 latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
 latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
 usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-E] [+|-e s] [+|-f[gG]]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
 [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
  -?|-h list help          -a AND selections (OR)     -b avoid kernel blocks
  -c c  cmd c ^c /c/[bix]  +c w  COMMAND width (9)    +d s  dir s files
  -d s  select by FD set   +D D  dir D tree *SLOW?*   +|-e s  exempt s *RISKY*
  -i select IPv[46] files  -K [i] list|(i)gn tasKs    -l list UID numbers
  -n no host names         -N select NFS files        -o list file offset
  -O no overhead *RISKY*   -P no port names           -R list paRent PID
  -s list file size        -t terse listing           -T disable TCP/TPI info
  -U select Unix socket    -v list version info       -V verbose search
  +|-w  Warnings (+)       -X skip TCP&UDP* files     -Z Z  context [Z]
  -- end option scan     
  -E display endpoint info              +E display endpoint info and files
  +f|-f  +filesystem or -file names     +|-f[gG] flaGs 
  -F [f] select fields; -F? for help  
  +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)
                                        +m [m] use|create mount supplement
  +|-M   portMap registration (-)       -o o   o 0t offset digits (8)
  -p s   exclude(^)|select PIDs         -S [t] t second stat timeout (15)
  -T qs TCP/TPI Q,St (s) info
  -g [s] exclude(^)|select and print process group IDs
  -i i   select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]
  +|-r [t[m<fmt>]] repeat every t seconds (15);  + until no files, - forever.
       An optional suffix to t is m<fmt>; m must separate t from <fmt> and
      <fmt> is an strftime(3) format for the marker line.
  -s p:s  exclude(^)|select protocol (p = TCP|UDP) states by name(s).
  -u s   exclude(^)|select login|UID set s
  -x [fl] cross over +d|+D File systems or symbolic Links
  names  select named files or files on named file systems
Anyone can list all files; /dev warnings disabled; kernel ID check disabled.
[root@localhost 桌面]# 

The parameters commonly used in conjunction with commands are:

  1. View the corresponding process of a port: lsof -i:port:

  1. View a port of a protocol: lsof -i protocol: port:

netstat command

netstat command to view network status:

netstat --help :

  1. View the network status and process information of the port: netstat -a |grep port

-a; Display all connected sockets; grep finds the following content in the returned information

Generally, through this command, you can query the process of the following keywords, but you don’t know the monitoring status of the port.

telnet command

In addition to the above methods to confirm the status of a port, you can also use the telnet command to confirm the port opening status on a remote host:

telnet ip port:

In the above picture, you can only confirm that you can’t connect, but you can’t confirm whether it’s the host that can’t connect, or the port is not open for access. You can confirm it with the ping command:

If it can be pinged but cannot connect to the port, just check whether the process corresponding to the port is started and whether the port number is open. Open port number can refer to another article: https://blog.csdn.net/yeyuningzi/article/details/127546854

Guess you like

Origin blog.csdn.net/yeyuningzi/article/details/129437108