知乎專欄 | 多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者” |
netstat 監控TCP狀態
#netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’
狀態: 描述 CLOSED: 無連接是活動的或正在進行 LISTEN: 伺服器在等待進入呼叫 SYN_RECV: 一個連接請求已經到達,等待確認 SYN_SENT: 應用已經開始,打開一個連接 ESTABLISHED:正常數據傳輸狀態 FIN_WAIT1: 應用說它已經完成 FIN_WAIT2: 另一邊已同意釋放 ITMED_WAIT:等待所有分組死掉 CLOSING: 兩邊同時嘗試關閉 TIME_WAIT: 另一邊已初始化一個釋放 LAST_ACK: 等待所有分組死掉
# ss State Recv-Q Send-Q Local Address:Port Peer Address:Port CLOSE-WAIT 1 0 192.168.3.124:19644 130.75.116.209:http CLOSE-WAIT 1 0 192.168.3.124:31289 170.224.194.69:https CLOSE-WAIT 1 0 192.168.3.124:64903 198.20.8.241:https CLOSE-WAIT 1 0 192.168.3.124:64902 198.20.8.241:https CLOSE-WAIT 1 0 192.168.3.124:27528 170.224.160.205:https CLOSE-WAIT 1 0 192.168.3.124:10152 198.20.8.241:https CLOSE-WAIT 1 0 192.168.3.124:18263 170.224.194.69:http CLOSE-WAIT 1 0 192.168.3.124:18262 170.224.194.69:http CLOSE-WAIT 1 0 192.168.3.124:27792 129.89.61.70:http CLOSE-WAIT 1 0 192.168.3.124:27595 129.89.61.70:http CLOSE-WAIT 1 0 192.168.3.124:28970 129.89.61.70:http CLOSE-WAIT 1 0 192.168.3.124:28158 130.75.116.210:http CLOSE-WAIT 1 0 192.168.3.124:26186 130.75.116.210:http CLOSE-WAIT 1 0 192.168.3.124:26185 130.75.116.210:http CLOSE-WAIT 1 0 192.168.3.124:42563 74.125.71.99:http CLOSE-WAIT 1 0 192.168.3.124:42564 74.125.71.99:http CLOSE-WAIT 1 0 192.168.3.124:63459 130.75.116.202:http CLOSE-WAIT 1 0 192.168.3.124:63458 130.75.116.202:http ESTAB 0 0 192.168.3.124:30829 192.168.3.17:3260 ESTAB 0 0 192.168.3.124:13234 192.168.3.15:3260 ESTAB 0 0 ::ffff:192.168.3.124:ssh ::ffff:192.168.80.5:5 2682 ESTAB 0 1960 ::ffff:192.168.3.124:ssh ::ffff:192.168.80.5:5 2957 $ ss State Recv-Q Send-Q Local Address:Port Peer Address:Port ESTAB 0 0 192.168.80.1:38281 64.4.61.72:1863 ESTAB 0 0 192.168.80.1:54504 112.95.240.77:8000 ESTAB 0 0 192.168.80.1:14698 74.125.71.125:5222 ESTAB 0 0 192.168.80.1:14697 74.125.71.125:5222 ESTAB 0 0 192.168.80.1:54123 64.12.28.171:https ESTAB 0 0 192.168.80.1:4225 64.4.61.171:1863 ESTAB 0 0 192.168.80.1:ssh 192.168.80.5:51291 ESTAB 0 0 ::ffff:192.168.80.1:microsoft-ds ::ffff:192.168.80.5:51094 ESTAB 0 0 192.168.80.1:22074 205.188.1.241:https ESTAB 0 0 192.168.80.1:59340 64.4.34.213:1863 ESTAB 0 0 192.168.80.1:9766 91.189.89.114:https ESTAB 0 0 192.168.80.1:3300 64.4.44.78:1863
root@netkiller ~ % ss -itn State Recv-Q Send-Q Local Address:Port Peer Address:Port ESTAB 0 0 192.168.3.14:22 192.168.3.4:63044 cubic wscale:6,7 rto:212 rtt:10.681/8.769 ato:40 mss:1448 pmtu:1500 rcvmss:1392 advmss:1448 cwnd:10 ssthresh:16 bytes_acked:33428 bytes_received:9337 segs_out:377 segs_in:522 data_segs_out:360 data_segs_in:160 send 10.8Mbps lastsnd:68 lastrcv:72 lastack:56 pacing_rate 13.0Mbps delivery_rate 20.8Mbps app_limited busy:668ms rcv_rtt:7 rcv_space:28960 rcv_ssthresh:45776 minrtt:1.302
CentOS
# yum install nload -y
Ubuntu
# sudo apt-get install nload
運行監控命令
# nload
Device eth0 [172.16.3.90] (1/5): ============================================================================= Incoming: Curr: 10.00 kBit/s Avg: 103.95 kBit/s Min: 0.00 Bit/s || Max: 3.23 MBit/s ## Ttl: 1090.93 GByte Outgoing: Curr: 12.84 kBit/s Avg: 15.29 kBit/s Min: 0.00 Bit/s Max: 206.63 kBit/s Ttl: 48.57 GByte
Bandwidth Monitor 1.1.0 Iface RX(KB/sec) TX(KB/sec) Total(KB/sec) lo 8.366 8.366 16.732 eth0 24.120 100.005 124.125 eth1 0.000 0.000 0.000 Total 32.486 108.371 140.857 Hit CTRL-C to end this madness.
# yum install iptstate -y
IPTState - IPTables State Top Version: 2.2.2 Sort: SrcIP b: change sorting h: help Source Destination Prt State TTL 0.0.0.0 224.0.0.1 igmp 0:09:49 192.168.2.1:45981 192.168.2.1:22 tcp TIME_WAIT 0:01:33 192.168.2.1:46009 192.168.2.1:22 tcp TIME_WAIT 0:01:57 192.168.2.1:45915 192.168.2.1:22 tcp TIME_WAIT 0:00:58 192.168.2.1:45975 192.168.2.1:22 tcp TIME_WAIT 0:01:31 192.168.2.1:54922 202.141.160.110:80 tcp TIME_WAIT 0:00:57 192.168.2.1:46000 192.168.2.1:22 tcp TIME_WAIT 0:01:54 192.168.2.1:45973 192.168.2.1:22 tcp TIME_WAIT 0:01:31 192.168.2.1:45855 192.168.2.1:22 tcp TIME_WAIT 0:00:26 192.168.2.1:45990 192.168.2.1:22 tcp TIME_WAIT 0:01:36 192.168.2.1:45822 192.168.2.1:22 tcp TIME_WAIT 0:00:01 192.168.2.1:45926 192.168.2.1:22 tcp TIME_WAIT 0:01:01