netstat命令使用

来源:互联网 发布:提问软件 编辑:程序博客网 时间:2024/05/17 03:21
netstat命令用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况,是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告。命令格式:netstat [选项][-A<网络类型>][--ip]选项:-a或–all 显示所有连线中的Socket。-A<网络类型>或–<网络类型> 列出该网络类型连线中的相关地址。-c或–continuous 持续列出网络状态。-C或–cache 显示路由器配置的快取信息。-e或–extend 显示网络其他相关信息。-F或–fib 显示FIB。-g或–groups 显示多重广播功能群组组员名单。-h或–help 在线帮助。-i或–interfaces 显示网络界面信息表单。-l或–listening 显示监控中的服务器的Socket。-M或–masquerade 显示伪装的网络连线。-n或–numeric 直接使用IP地址,而不通过域名服务器。-N或–netlink或–symbolic 显示网络硬件外围设备的符号连接名称。-o或–timers 显示计时器。-p或–programs 显示正在使用Socket的程序识别码和程序名称。-r或–route 显示Routing Table。-s或–statistice 显示网络工作信息统计表。-t或–tcp 显示TCP传输协议的连线状况。-u或–udp 显示UDP传输协议的连线状况。-v或–verbose 显示指令执行过程。-V或–version 显示版本信息。-w或–raw 显示RAW传输协议的连线状况。-x或–unix 此参数的效果和指定”-A unix”参数相同。–ip或–inet 此参数的效果和指定”-A inet”参数相同。实例:无参数使用[root@localhost ~]# netstatActive Internet connections (w/o servers)Proto Recv-Q Send-Q Local Address               Foreign Address             State      tcp        0    268 192.168.120.204:ssh         10.2.0.68:62420             ESTABLISHED udp        0      0 192.168.120.204:4371        10.58.119.119:domain        ESTABLISHED Active UNIX domain sockets (w/o servers)Proto RefCnt Flags       Type       State         I-Node Pathunix  2      [ ]         DGRAM                    1491   @/org/kernel/udev/udevdunix  4      [ ]         DGRAM                    7337   /dev/logunix  2      [ ]         DGRAM                    708823 unix  2      [ ]         DGRAM                    7539   unix  3      [ ]         STREAM     CONNECTED     7287   unix  3      [ ]         STREAM     CONNECTED     7286   说明:从整体上看,netstat的输出结果可以分为两个部分:一个是Active Internet connections,称为有源TCP连接,其中"Recv-Q"和"Send-Q"指的是接收队列和发送队列。这些数字一般都应该是0。如果不是则表示软件包正在队列中堆积。这种情况只能在非常少的情况见到。另一个是Active UNIX domain sockets,称为有源Unix域套接口(和网络套接字一样,但是只能用于本机通信,性能可以提高一倍)。Proto显示连接使用的协议,RefCnt表示连接到本套接口上的进程号,Types显示套接口的类型,State显示套接口当前的状态,Path表示连接到套接口的其它进程使用的路径名。套接口类型:-t :TCP-u :UDP-raw :RAW类型--unix :UNIX域类型--ax25 :AX25类型--ipx :ipx类型--netrom :netrom类型状态说明:LISTEN:侦听来自远方的TCP端口的连接请求SYN-SENT:再发送连接请求后等待匹配的连接请求(如果有大量这样的状态包,检查是否中招了)SYN-RECEIVED:再收到和发送一个连接请求后等待对方对连接请求的确认(如有大量此状态,估计被flood攻击了)ESTABLISHED:代表一个打开的连接FIN-WAIT-1:等待远程TCP连接中断请求,或先前的连接中断请求的确认FIN-WAIT-2:从远程TCP等待连接中断请求CLOSE-WAIT:等待从本地用户发来的连接中断请求CLOSING:等待远程TCP对连接中断的确认LAST-ACK:等待原来的发向远程TCP的连接中断请求的确认(不是什么好东西,此项出现,检查是否被攻击)TIME-WAIT:等待足够的时间以确保远程TCP接收到连接中断请求的确认CLOSED:没有任何连接状态实例:列出所有端口[root@localhost ~]# netstat -aActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address               Foreign Address             State      tcp        0      0 localhost:smux              *:*                         LISTEN      tcp        0      0 *:svn                       *:*                         LISTEN      tcp        0      0 *:ssh                       *:*                         LISTEN      tcp        0    284 192.168.120.204:ssh         10.2.0.68:62420             ESTABLISHED udp        0      0 localhost:syslog            *:*                                     udp        0      0 *:snmp                      *:*                                     Active UNIX domain sockets (servers and established)Proto RefCnt Flags       Type       State         I-Node Pathunix  2      [ ACC ]     STREAM     LISTENING     708833 /tmp/ssh-yKnDB15725/agent.15725unix  2      [ ACC ]     STREAM     LISTENING     7296   /var/run/audispd_eventsunix  2      [ ]         DGRAM                    1491   @/org/kernel/udev/udevdunix  4      [ ]         DGRAM                    7337   /dev/logunix  2      [ ]         DGRAM                    708823 unix  2      [ ]         DGRAM                    7539   unix  3      [ ]         STREAM     CONNECTED     7287   unix  3      [ ]         STREAM     CONNECTED     7286   实例:显示网络统计信息[root@localhost ~]# netstat -sIp:    530999 total packets received    0 forwarded    0 incoming packets discarded    530999 incoming packets delivered    8258 requests sent out    1 dropped because of missing routeIcmp:    90 ICMP messages received    0 input ICMP message failed.    ICMP input histogram:        destination unreachable: 17        echo requests: 1        echo replies: 72    106 ICMP messages sent    0 ICMP messages failed    ICMP output histogram:        destination unreachable: 8        echo request: 97        echo replies: 1IcmpMsg:        InType0: 72        InType3: 17        InType8: 1        OutType0: 1        OutType3: 8        OutType8: 97Tcp:    8 active connections openings    15 passive connection openings    8 failed connection attempts    3 connection resets received    1 connections established    3132 segments received    2617 segments send out    53 segments retransmited    0 bad segments received.    252 resets sentUdp:    0 packets received    0 packets to unknown port received.    0 packet receive errors    5482 packets sentTcpExt:    1 invalid SYN cookies received    1 TCP sockets finished time wait in fast timer    57 delayed acks sent    Quick ack mode was activated 50 times    60 packets directly queued to recvmsg prequeue.    68 packets directly received from backlog    4399 packets directly received from prequeue    520 packets header predicted    51 packets header predicted and directly queued to user    1194 acknowledgments not containing data received    21 predicted acknowledgments    0 TCP data loss events    1 timeouts after reno fast retransmit    9 retransmits in slow start    42 other TCP timeouts    3 connections aborted due to timeoutIpExt:    InBcastPkts: 527777说明:按照各个协议分别显示其统计数据。如果我们的应用程序(如Web浏览器)运行速度比较慢,或者不能显示Web页之类的数据,那么我们就可以用本选项来查看一下所显示的信息。我们需要仔细查看统计数据的各行,找到出错的关键字,进而确定问题所在。实例:显示监听的套接口[root@localhost ~]# netstat -lActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address               Foreign Address             State      tcp        0      0 localhost:smux              *:*                         LISTEN      tcp        0      0 *:svn                       *:*                         LISTEN      tcp        0      0 *:ssh                       *:*                         LISTEN      udp        0      0 localhost:syslog            *:*                                     udp        0      0 *:snmp                      *:*                                     Active UNIX domain sockets (only servers)Proto RefCnt Flags       Type       State         I-Node Pathunix  2      [ ACC ]     STREAM     LISTENING     708833 /tmp/ssh-yKnDB15725/agent.15725unix  2      [ ACC ]     STREAM     LISTENING     7296   /var/run/audispd_events实例:显示所有已建立的有效连接[root@localhost ~]# netstat -nActive Internet connections (w/o servers)Proto Recv-Q Send-Q Local Address               Foreign Address             State      tcp        0    268 192.168.120.204:22          10.2.0.68:62420             ESTABLISHED Active UNIX domain sockets (w/o servers)Proto RefCnt Flags       Type       State         I-Node Pathunix  2      [ ]         DGRAM                    1491   @/org/kernel/udev/udevdunix  4      [ ]         DGRAM                    7337   /dev/logunix  2      [ ]         DGRAM                    708823 unix  2      [ ]         DGRAM                    7539   unix  3      [ ]         STREAM     CONNECTED     7287   实例:显示关于以太网的统计数据[root@localhost ~]# netstat -eActive Internet connections (w/o servers)Proto Recv-Q Send-Q Local Address               Foreign Address             State       User       Inode     tcp        0    248 192.168.120.204:ssh         10.2.0.68:62420             ESTABLISHED root       708795     Active UNIX domain sockets (w/o servers)Proto RefCnt Flags       Type       State         I-Node Pathunix  2      [ ]         DGRAM                    1491   @/org/kernel/udev/udevdunix  4      [ ]         DGRAM                    7337   /dev/logunix  2      [ ]         DGRAM                    708823 unix  2      [ ]         DGRAM                    7539   unix  3      [ ]         STREAM     CONNECTED     7287   unix  3      [ ]         STREAM     CONNECTED     7286   说明:用于显示关于以太网的统计数据。它列出的项目包括传送的数据报的总字节数、错误数、删除数、数据报的数量和广播的数量。这些统计数据既有发送的数据报数量,也有接收的数据报数量。这个选项可以用来统计一些基本的网络流量)实例:显示关于路由表的信息[root@localhost ~]# netstat -rKernel IP routing tableDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface192.168.120.0   *               255.255.255.0   U         0 0          0 eth0192.168.0.0     192.168.120.1   255.255.0.0     UG        0 0          0 eth010.0.0.0        192.168.120.1   255.0.0.0       UG        0 0          0 eth0default         192.168.120.240 0.0.0.0         UG        0 0          0 eth0来自:http://www.cnblogs.com/peida/archive/2013/03/08/2949194.html

0 0
原创粉丝点击