首页 > 系统相关 >网络工具netstat与ss

网络工具netstat与ss

时间:2022-12-16 08:44:21浏览次数:40  
标签:ss 网络工具 netstat sockets -- display wait

建议使用ss命令,2001年的时候netstat 1.42版本之后就没更新了,之后取代的工具是ss。netstat命令在很多场景下比较慢。ss可以显示跟netstat类似的信息,但是速度却比netstat快很多,netstat是基于/proc/net/tcp获取 信息,而ss是直接从内核读取信息。

Recv-Q Send-Q

netstat与ss 都有这两列,特别重要的两组数据,看看这两列的说明
Recv-Q
Established: The count of bytes not copied by the user program connected to this socket.
Listening: Since Kernel 2.6.18 this column contains the current syn backlog.

Send-Q
Established: The count of bytes not acknowledged by the remote host.
Listening: Since Kernel 2.6.18 this column contains the maximum size of the syn backlog.

可以看到如果连接时Established状态
Recv-Q 指收到的数据还在缓存中,还没被进程读取,这个值就是还没被进程读取的 bytes
Send-Q 指发送队列中没有被远程主机确认的 bytes

如果连接时Listening状态的话
Recv-Q 指当前syn半连接队列的大小
Send-Q 指syn半连接的最大容量

这个就能推到出很多我们平常调试中甩锅的的情况
比如我们压测中,指标一直上不去,Send-Q 有积压,那么大概率是对方机器到瓶颈了,如果 Recv-Q 有积压,大概率是自己的机器有问题。或者在Listening状态下,Recv-Q 积压越来越多,可以相应放大半连接队列的大小。

netstat 命令

netstat -h
usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
       netstat [-vWnNcaeol] [<Socket> ...]
       netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]

        -r, --route              display routing table
        -I, --interfaces=<Iface> display interface table for <Iface>
        -i, --interfaces         display interface table
        -g, --groups             display multicast group memberships
        -s, --statistics         display networking statistics (like SNMP)
        -M, --masquerade         display masqueraded connections

        -v, --verbose            be verbose
        -W, --wide               don't truncate IP addresses
        -n, --numeric            don't resolve names
        --numeric-hosts          don't resolve host names
        --numeric-ports          don't resolve port names
        --numeric-users          don't resolve user names
        -N, --symbolic           resolve hardware names
        -e, --extend             display other/more information
        -p, --programs           display PID/Program name for sockets
        -o, --timers             display timers
        -c, --continuous         continuous listing

        -l, --listening          display listening server sockets
        -a, --all                display all sockets (default: connected)
        -F, --fib                display Forwarding Information Base (default)
        -C, --cache              display routing cache instead of FIB
        -Z, --context            display SELinux security context for sockets
经常使用的 netstat -altp
a 显示所有的链接
l 显示listening状态的链接
t 仅显示TCP
p 显示PID和项目名

ss 命令

ss -h
Usage: ss [ OPTIONS ]
       ss [ OPTIONS ] [ FILTER ]
   -h, --help          this message
   -V, --version       output version information
   -n, --numeric       don't resolve service names
   -r, --resolve       resolve host names
   -a, --all           display all sockets
   -l, --listening     display listening sockets
   -o, --options       show timer information
   -e, --extended      show detailed socket information
   -m, --memory        show socket memory usage
   -p, --processes     show process using socket
   -i, --info          show internal TCP information
   -s, --summary       show socket usage summary
   -b, --bpf           show bpf filter socket information
   -E, --events        continually display sockets as they are destroyed
   -Z, --context       display process SELinux security contexts
   -z, --contexts      display process and socket SELinux security contexts
   -N, --net           switch to the specified network namespace name

   -4, --ipv4          display only IP version 4 sockets
   -6, --ipv6          display only IP version 6 sockets
   -0, --packet        display PACKET sockets
   -t, --tcp           display only TCP sockets
   -S, --sctp          display only SCTP sockets
   -u, --udp           display only UDP sockets
   -d, --dccp          display only DCCP sockets
   -w, --raw           display only RAW sockets
   -x, --unix          display only Unix domain sockets
       --vsock         display only vsock sockets
   -f, --family=FAMILY display sockets of type FAMILY
       FAMILY := {inet|inet6|link|unix|netlink|vsock|help}

   -K, --kill          forcibly close sockets, display what was closed
   -H, --no-header     Suppress header line

   -A, --query=QUERY, --socket=QUERY
       QUERY := {all|inet|tcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink|vsock_stream|vsock_dgram}[,QUERY]

   -D, --diag=FILE     Dump raw information about TCP sockets to FILE
   -F, --filter=FILE   read filter information from FILE
       FILTER := [ state STATE-FILTER ] [ EXPRESSION ]
       STATE-FILTER := {all|connected|synchronized|bucket|big|TCP-STATES}
         TCP-STATES := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|closed|close-wait|last-ack|listen|closing}
          connected := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|close-wait|last-ack|closing}
       synchronized := {established|syn-recv|fin-wait-{1,2}|time-wait|close-wait|last-ack|closing}
             bucket := {syn-recv|time-wait}
                big := {established|syn-sent|fin-wait-{1,2}|closed|close-wait|last-ack|listen|closing}
经常使用的 ss -lnt
l 显示listening状态的链接
t 仅显示TCP
n 不要解析服务名称

标签:ss,网络工具,netstat,sockets,--,display,wait
From: https://www.cnblogs.com/feixiangmanon/p/16986458.html

相关文章

  • S1 - Lesson 101 - 102
    WordsScotlandTheUnitedKingdomofGreatBritainandNorthernIreland cardbusinesscardcreditcardbankcardidcard youthyoung hostel[招待所,旅......
  • 01-html&CSS
    常用标签介绍  font<body><!--字体标签需求1:在网页上显示我是字体标签,并修改字体为宋体,颜色为红色。font标签是字体标签,它可以用来修改文本的字体,颜......
  • ssm报错Could not open JDBC Connection for transaction; nested exception is com.m
    HTTPStatus500-Requestprocessingfailed;nestedexceptionisorg.springframework.transaction.CannotCreateTransactionException:CouldnotopenJDBCConnecti......
  • go会话控制(session)
    session机制是一种服务器端的机制,服务器使用一种类似于散列表的结构(map)来保存信息。当程序需要为某个客户端的请求创建一个session的时候,服务器首先检查这个客户端的请......
  • C#内联函数 特性 MethodImplOptions.AggressiveInlining)
    https://www.cnblogs.com/cdaniu/p/15900255.htmlImpl:implement的缩写内联函数在计算机科学中,内联函数(有时称作在线函数或编译时期展开函数)是一种编程语言结构,用来建议......
  • MethodImplOptions.AggressiveInlining如果一个昂贵的参数没有被使用,它能阻止它被评估
    内联在这里没有帮助你现在的代码是voidLog(stringmessage,LogLevellogLevel){if(logLevel>=chosenLogLevel)Console.WriteLine(message);}void......
  • docker安装minio OSS文件存储服务
    查看minio的docker版本使用docker命令查看minio的版本dockersearchminio拉取镜像dockerpullminio/minio创建目录:一个用来存放配置,一个用来存储上传文件的目录......
  • S1 - Lesson 99 - 100
    Wordsow slipbecarefulslipperyfloorcautionwetfloor  downstairsgodownstairs hurthurthurthurt backmybackthebackdoor strandup ......
  • Express 简介、安装、使用和案例
    Express是什么express 是一个快速,简单,极简的node.js 应用开发框架,通过它,可以轻松构建各种 Web 应用(后端)。例如:接口服务传统的Web网站开发工具集成官网:​​http://expre......
  • 配置ssl访问(https)
    简要记录主要步骤备忘1、进入到jdk下的bin目录2、输入如下指令keytool-v-genkey-aliastomcat-keyalgRSA-keystored:/tomcat.keystore  -validity36500附:d:......