`
victorwmh
  • 浏览: 208069 次
  • 性别: Icon_minigender_1
  • 来自: 宇宙
社区版块
存档分类
最新评论

netstat命令详解

阅读更多

netstat命令用于显示IP、TCP、UDP和ICMP协议相关的统计数据,对我们诊断服务器和应用程序的运行状况非常有用。

 

一、netstat参数含义

[root@208 ~]# netstat -help

 

usage: netstat [-veenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
       netstat [-vnNcaeol] [<Socket> ...]
       netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [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
        -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
        -c, --continuous           continuous listing

        -l, --listening            display listening server sockets
        -a, --all, --listening     display all sockets (default: connected)
        -o, --timers               display timers
        -F, --fib                  display Forwarding Information Base (default)
        -C, --cache                display routing cache instead of FIB
        -T, --notrim               stop trimming long addresses
        -Z, --context              display SELinux security context for sockets

  <Iface>: Name of interface to monitor/list.
  <Socket>={-t|--tcp} {-u|--udp} {-S|--sctp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom
  <AF>=Use '-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) 

 

 

常用选项 

-s 本选项能够按照各个协议分别显示其统计数据。如果你的应用程序(如Web浏览器)运行速度比较慢,或者不能显示Web页之类的数据,那么你就可以用本选项来查看一下所显示的信息。你需要仔细查看统计数据的各行,找到出错的关键字,进而确定问题所在。 

 

-e 本选项用于显示关于以太网的统计数据。它列出的项目包括传送的数据报的总字节数、错误数、删除数、数据报的数量和广播的数量。这些统计数据既有发送的数据报数量,也有接收的数据报数量。这个选项可以用来统计一些基本的网络流量。 

 

-r 本选项可以显示关于路由表的信息,类似于后面所讲使用route print命令时看到的 信息。除了显示有效路由外,还显示当前有效的连接。

 

-a 本选项显示一个所有的有效连接信息列表,包括已建立的连接(ESTABLISHED),也包括监听连接请求(LISTENING)的那些连接,断开连接(CLOSE_WAIT)或者处于联机等待状态的(TIME_WAIT)等。

 

-n 显示所有已建立的有效连接。netstat支持用于显示活动或被动套接字的选项集。选项-t、-u、-w和-x分别表示TCP、UDP、RAW和UNIX套接字连接。如果你另外还提供了一个-a标记,还会显示出等待连接(也就是说处于监听模式)的套接字。这样就可以得到一份服务器清单,当前所有运行于系统中的所有服务器都会列入其中。 

 

 

二、用法实例
1、查找某个端口的活动连接

[root@208 ~]# netstat -ano|grep 9100

 

tcp        0      0 :::9100                     :::*                        LISTEN      off (0.00/0/0)
tcp        0      0 ::ffff:192.168.0.208:9100   ::ffff:192.168.0.226:4903   ESTABLISHED keepalive (5575.21/0/0)
tcp        0      0 ::ffff:192.168.0.208:9100   ::ffff:192.168.0.236:2343   ESTABLISHED keepalive (4703.56/0/0)
tcp        0      0 ::ffff:192.168.0.208:9100   ::ffff:192.168.0.235:2765   ESTABLISHED keepalive (5654.58/0/0)
tcp        0      0 ::ffff:192.168.0.208:9100   ::ffff:192.168.0.235:2869   ESTABLISHED keepalive (6246.16/0/0)

 
2、查看TCP端口的监听程序

 

[root@nccd208 ~]# netstat -tlnp

 

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1787/rpcbind        
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2186/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2079/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2295/master         
tcp        0      0 0.0.0.0:55681               0.0.0.0:*                   LISTEN      1970/rpc.statd      
tcp        0      0 192.168.0.208:9000          0.0.0.0:*                   LISTEN      2335/python         
tcp        0      0 127.0.0.1:9001              0.0.0.0:*                   LISTEN      2340/python         
tcp        0      0 :::8011                     :::*                        LISTEN      28354/java          
tcp        0      0 :::9100                     :::*                        LISTEN      28354/java          
tcp        0      0 :::8012                     :::*                        LISTEN      28354/java          
tcp        0      0 :::1521                     :::*                        LISTEN      2457/tnslsnr        
tcp        0      0 :::22                       :::*                        LISTEN      2186/sshd           
tcp        0      0 ::1:631                     :::*                        LISTEN      2079/cupsd          
tcp        0      0 :::10936                    :::*                        LISTEN      2733/ora_d000_nccd  
tcp        0      0 ::ffff:127.0.0.1:8001       :::*                        LISTEN      1705/java           
tcp        0      0 :::8003                     :::*                        LISTEN      1705/java           
tcp        0      0 :::9091                     :::*                        LISTEN      1705/java           
tcp        0      0 ::ffff:127.0.0.1:8004       :::*                        LISTEN      27851/java          
tcp        0      0 :::8005                     :::*                        LISTEN      27851/java          
tcp        0      0 :::8006                     :::*                        LISTEN      27851/java          
tcp        0      0 :::30214                    :::*                        LISTEN      1970/rpc.statd      
tcp        0      0 ::ffff:127.0.0.1:8007       :::*                        LISTEN      26936/java          
tcp        0      0 :::8008                     :::*                        LISTEN      26936/java          
tcp        0      0 :::8009                     :::*                        LISTEN      26936/java          
tcp        0      0 ::ffff:127.0.0.1:8010       :::*                        LISTEN      28354/java 

 

 延伸阅读:《netstat命令示例详解

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics