“Linux netstat”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
 
第22行: 第22行:
 
===查看端口占用===
 
===查看端口占用===
 
<syntaxhighlight lang="shell-session">
 
<syntaxhighlight lang="shell-session">
[root@iZ8vbcjkeqbrdmmbt23vboZ ~]# netstat -nlp|grep 80
+
[root@iZ8vbcjkeqbrdmmbt23vboZ ~]# netstat -nlp|grep -P ":80\b"
tcp        0      0 172.17.0.1:10808        0.0.0.0:*              LISTEN      22268/./v2ray     
+
tcp        0      0 0.0.0.0:80              0.0.0.0:*              LISTEN      13690/docker-proxy
tcp        0      0 0.0.0.0:80              0.0.0.0:*              LISTEN      13690/docker-proxy
+
</syntaxhighlight>netstat
unix  2      [ ACC ]    STREAM    LISTENING    15703173 13701/containerd-sh  /run/containerd/s/3abe05f9787ef00f3cc68fb59e1c38fb4512c80abd3ac5485839050ef73dfd21
 
unix  2      [ ACC ]    STREAM    LISTENING    16261380 8398/aliyun-service  /tmp/aliyun_assist_service.sock
 
  
</syntaxhighlight><syntaxhighlight lang="shell-session">
+
* -n, --numeric            don't resolve names
root@aade5ae73079:/var/www/html# netstat -apn|grep ":443"
+
* -l, --listening          display listening server sockets
tcp        0      0 0.0.0.0:443            0.0.0.0:*               LISTEN      1/apache2
+
* -p, --programs           display PID/Program name for sockets
</syntaxhighlight>-n, --numeric            don't resolve names
+
* -a, --all                display all sockets (default: connected)
  
-l, --listening          display listening server sockets
 
  
-p, --programs           display PID/Program name for sockets
+
grep
  
-a, --all                display all sockets (default: connected)
+
* -P, --perl-regexp         PATTERN is a Perl regular expression
 +
 
 +
正则表达式中的 “\b”匹配一个单词边界,也就是指单词和空格间的位置。例如, 'er\b' 可以匹配"never" 中的 'er',但不能匹配 "verb" 中的 'er'。

2023年2月11日 (六) 10:30的最新版本

安装

root@aade5ae73079:/var/www/html# apt -y install net-tools
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  net-tools
0 upgraded, 1 newly installed, 0 to remove and 50 not upgraded.
Need to get 250 kB of archives.
After this operation, 1015 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 net-tools amd64 1.60+git20181103.0eebece-1 [250 kB]
Fetched 250 kB in 3s (99.0 kB/s)                             
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package net-tools.
(Reading database ... 19912 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20181103.0eebece-1_amd64.deb ...
Unpacking net-tools (1.60+git20181103.0eebece-1) ...
Setting up net-tools (1.60+git20181103.0eebece-1) ...

查看端口占用

[root@iZ8vbcjkeqbrdmmbt23vboZ ~]# netstat -nlp|grep -P ":80\b"
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13690/docker-proxy

netstat

  • -n, --numeric            don't resolve names
  • -l, --listening          display listening server sockets
  • -p, --programs           display PID/Program name for sockets
  • -a, --all                display all sockets (default: connected)


grep

  • -P, --perl-regexp         PATTERN is a Perl regular expression

正则表达式中的 “\b”匹配一个单词边界,也就是指单词和空格间的位置。例如, 'er\b' 可以匹配"never" 中的 'er',但不能匹配 "verb" 中的 'er'。