1.netstat详细说明
[wm@adx ~]$ netstat -help
usage: netstat [-veenNcCF] [] -r netstat {-V|--version|-h|--help}
netstat [-vnNcaeol] [ ...]
netstat { [-veenNac] -I[] | [-veenNac] -i | [-cnNe] -M | -s } [delay]
-r, --route display routing table
-I, --interfaces=[] display interface table for
-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
: Name of interface to monitor/list.
={-t|--tcp} {-u|--udp} {-S|--sctp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom
=Use '-A ' or '--'; 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)
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 没有任何连接状态
[wm@adx ~]$ netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:9312 *:* LISTEN
tcp 0 0 localhost.localdomain:2208 *:* LISTEN
tcp 0 0 *:nfs *:* LISTEN
tcp 0 0 *:31940 *:* LISTEN
tcp 0 0 *:27017 *:* LISTEN
tcp 0 0 *:rsync *:* LISTEN
udp 0 0 *:mdns *:*
udp 0 0 *:sunrpc *:*
udp 0 0 *:ipp *:*
udp 0 0 *:26001 *:*
udp 0 0 *:45008 *:*
udp 0 0 *:mdns *:*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 5026 @ISCSIADM_ABSTRACT_NAMESPACE
unix 2 [ ACC ] STREAM LISTENING 7275 /tmp/.font-unix/fs7100
unix 2 [ ACC ] STREAM LISTENING 7584 /tmp/mysql_cluster.sock
unix 2 [ ACC ] STREAM LISTENING 36185327 /tmp/mongodb-27017.sock
unix 2 [ ACC ] STREAM LISTENING 7408 /var/run/avahi-daemon/socket
unix 2 [ ACC ] STREAM LISTENING 5010 @ISCSID_UIP_ABSTRACT_NAMESPACE
[wm@adx ~]$ netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:9312 *:* LISTEN
tcp 0 0 localhost.localdomain:2208 *:* LISTEN
[wm@adx ~]$ netstat -au
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 *:53505 *:*
udp 0 0 *:nfs *:*
udp 0 0 *:tinc *:*
udp 0 0 *:tenfold *:*
udp 0 0 *:22090 *:*
udp 0 0 *:717 *:*
[wm@adx ~]$ netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:9312 *:* LISTEN
tcp 0 0 localhost.localdomain:2208 *:* LISTEN
tcp 0 0 *:nfs *:* LISTEN
tcp 0 0 *:31940 *:* LISTEN
tcp 0 0 *:27017 *:* LISTEN
udp 0 0 *:732 *:*
udp 0 0 *:mdns *:*
udp 0 0 *:sunrpc *:*
udp 0 0 *:ipp *:*
udp 0 0 *:26001 *:*
udp 0 0 *:45008 *:*
udp 0 0 *:mdns *:*
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 5026 @ISCSIADM_ABSTRACT_NAMESPACE
unix 2 [ ACC ] STREAM LISTENING 7275 /tmp/.font-unix/fs7100
unix 2 [ ACC ] STREAM LISTENING 7584 /tmp/mysql_cluster.sock
unix 2 [ ACC ] STREAM LISTENING 36185327 /tmp/mongodb-27017.sock
unix 2 [ ACC ] STREAM LISTENING 7408 /var/run/avahi-daemon/socket
unix 2 [ ACC ] STREAM LISTENING 5010 @ISCSID_UIP_ABSTRACT_NAMESPACE
unix 2 [ ACC ] STREAM LISTENING 6085 /var/run/dbus/system_bus_socket
[wm@adx ~]$ netstat -lt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:9312 *:* LISTEN
tcp 0 0 localhost.localdomain:2208 *:* LISTEN
tcp 0 0 *:nfs *:* LISTEN
tcp 0 0 *:31940 *:* LISTEN
tcp 0 0 *:27017 *:* LISTEN
[wm@adx ~]$ netstat -lu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 *:53505 *:*
udp 0 0 *:nfs *:*
udp 0 0 *:tinc *:*
udp 0 0 *:tenfold *:*
[wm@adx ~]$ netstat -lx
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 5026 @ISCSIADM_ABSTRACT_NAMESPACE
unix 2 [ ACC ] STREAM LISTENING 7275 /tmp/.font-unix/fs7100
unix 2 [ ACC ] STREAM LISTENING 7584 /tmp/mysql_cluster.sock
unix 2 [ ACC ] STREAM LISTENING 36185327 /tmp/mongodb-27017.sock
unix 2 [ ACC ] STREAM LISTENING 7408 /var/run/avahi-daemon/socket
unix 2 [ ACC ] STREAM LISTENING 5010 @ISCSID_UIP_ABSTRACT_NAMESPACE
[wm@adx ~]$ netstat -s
Ip:
166117795 total packets received
185973 with invalid addresses
0 forwarded
0 incoming packets discarded
164139417 incoming packets delivered
168224270 requests sent out
62 dropped because of missing route
5266 reassemblies required
2115 packets reassembled ok
5 fragments received ok
16 fragments created
Icmp:
290668 ICMP messages received
357 input ICMP message failed.
399276 connections reset due to unexpected data
1353140 connections reset due to early user close
1496632 connections aborted due to timeout
IpExt:
InMcastPkts: 3805
OutMcastPkts: 39
InBcastPkts: 1027863
OutBcastPkts: 17
[wm@adx ~]$ netstat -st
IcmpMsg:
InType0: 57
InType3: 289139
InType8: 1451
InType11: 12
InType13: 4
InType15: 2
InType17: 3
OutType0: 1451
OutType3: 267912
OutType8: 770
OutType14: 4
Tcp:
4326140 active connections openings
3275617 passive connection openings
1575982 failed connection attempts
1357965 connection resets received
[wm@adx ~]$ netstat -su
IcmpMsg:
InType0: 57
InType3: 289139
InType8: 1451
InType11: 12
InType13: 4
InType15: 2
InType17: 3
OutType0: 1451
OutType3: 267912
OutType8: 770
OutType14: 4
Udp:
10547358 packets received
268472 packets to unknown port received.
636095 packet receive errors
14253582 packets sent
IpExt:
InMcastPkts: 3805
OutMcastPkts: 39
InBcastPkts: 1027876
OutBcastPkts: 17
[wm@adx ~]$
[wm@adx ~]$ sudo netstat -p
[sudo] password for wm:
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 10.1.172.10:ssh 192.168.8.90:59617 ESTABLISHED 10422/sshd
tcp 0 0 10.1.172.10:ssh 192.168.8.90:51381 ESTABLISHED 8856/sshd
tcp 0 0 10.1.172.10:6379 10.1.172.25:56109 ESTABLISHED 23546/./redis-serve
[wm@adx ~]$ netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:9312 0.0.0.0:* LISTEN
[wm@adx ~]$ netstat -c
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost.localdomain:smtp localhost.localdomain:45976 ESTABLISHED
tcp 0 0 10.1.172.10:ssh 192.168.8.90:59617 ESTABLISHED
tcp 0 0 10.1.172.10:ssh 192.168.8.90:51381 ESTABLISHED
netstat: no support for `AF IPX' on this system.
netstat: no support for `AF AX25' on this system.
netstat: no support for `AF X25' on this system.
netstat: no support for `AF NETROM' on this system.
[wm@adx ~]$ netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.*.172.0 * 255.255.255.0 U 0 0 0 eth0
169.*.0.0 * 255.255.0.0 U 0 0 0 eth0
default 10.*.172.254 0.0.0.0 UG 0 0 0 eth0
[root@adx ~]# netstat -ap | grep ssh
tcp 0 0 *:ssh *:* LISTEN 2460/sshd
tcp 0 0 10.1.172.10:ssh 192.168.8.90:59617 ESTABLISHED 10422/sshd
tcp 0 0 10.1.172.10:ssh 192.168.8.90:51381 ESTABLISHED 8856/sshd
[root@adx ~]# netstat -ap | grep ":59617"
tcp 0 0 10.1.172.10:ssh 192.168.8.90:59617 ESTABLISHED 10422/sshd
[root@adx ~]# netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 109950027 0 12 0 84347503 0 0 0 BMRU
lo 16436 0 61454319 0 0 0 61454319 0 0 0 LRU
[root@adx ~]# netstat -ie
Kernel Interface table
eth0 Link encap:Ethernet HWaddr 00:22:19:D4:CE:3B
inet addr:10.1.172.10 Bcast:10.1.172.255 Mask:255.255.255.0
inet6 addr: fe80::222:19ff:fed4:ce3b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:109950279 errors:0 dropped:12 overruns:0 frame:0
TX packets:84347593 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16318770580 (15.1 GiB) TX bytes:19733349393 (18.3 GiB)
Interrupt:169 Memory:dfdf0000-dfe00000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:61454345 errors:0 dropped:0 overruns:0 frame:0
TX packets:61454345 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5467632769 (5.0 GiB) TX bytes:5467632769 (5.0 GiB)
[root@adx ~]# netstat -nat | grep "192.168.8.90:22" |awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -20
[root@adx ~]# netstat -nat |awk '{print $6}'
established)
Foreign
LISTEN
LISTEN
LISTEN
[root@localhost workspace]# netstat -an | awk '/^tcp/ { ++S[$NF]} END {for(a in S) print a, S[a]}'
LISTEN 12
ESTABLISHED 1
[root@adx ~]# netstat -nat |awk '{print $6}'|sort|uniq -c
1 established)
17 ESTABLISHED
1 Foreign
21 LISTEN
3 SYN_SENT
1 TIME_WAIT
[root@adx ~]# netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
21 LISTEN
17 ESTABLISHED
2 SYN_SENT
1 TIME_WAIT
1 Foreign
1 established)
awk '{print $1}' access.log |sort|uniq -c|sort -nr|head -10