系统相关
首页 > 系统相关> > netstat 工具的使用

netstat 工具的使用

作者:互联网

一、安装

yum -y install net-tools    (可以生成ifconfig命令,netstat命令)

二、参数介绍

netstat命令用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告。

 

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

  <Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}
           {-x|--unix} --ax25 --ipx --netrom
  <AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet
  List of possible address families (which support routing):
    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25) 
    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP) 
    x25 (CCITT X.25) 

 

三、netstat -an

netstat -an命令能看到所有和本地计算机建立连接的IP,它包含四个部分:proto(连接方式)、local address(本地连接地址)、foreign address(和本地建立连接的地址)、state(当前端口状态)。通过这个命令的详细信息可以完全监控自己的计算机上的连接。

netstat -an命令显示的state(当前端口状态)有以下几种状态:

  LISTEN:侦听来自远方的TCP端口的连接请求
  SYN-SENT:再发送连接请求后等待匹配的连接请求
  SYN-RECEIVED:再收到和发送一个连接请求后等待对方对连接请求的确认
  ESTABLISHED:代表一个打开的连接
  FIN-WAIT-1:等待远程TCP连接中断请求,或先前的连接中断请求的确认
  FIN-WAIT-2:从远程TCP等待连接中断请求
  CLOSE-WAIT:等待从本地用户发来的连接中断请求
  CLOSING:等待远程TCP对连接中断的确认
  LAST-ACK:等待原来的发向远程TCP的连接中断请求的确认
  TIME-WAIT:等待足够的时间以确保远程TCP接收到连接中断请求的确认
  CLOSED:没有任何连接状态

 

 

标签:中断请求,--,netstat,TCP,display,使用,工具,连接
来源: https://www.cnblogs.com/zjz20/p/13489134.html