首页  

linux netstat     所属分类 linux 浏览量 812
whatis netstat 
Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
显示网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等


常用参数

-a (all),默认不显示LISTEN相关
-t (tcp)仅显示tcp 
-u (udp)仅显示udp 
-x unix端口
-n 不显示别名,显示数字 (不查询主机名称 速度快)
-l Listen (监听)状态

-p 程序名
-r 路由信息
-e 扩展信息,如uid等
-s 按协议进行统计
-c 运行时间间隔

LISTEN 和 LISTENING 状态只有用-a或者-l才能看到


netstat -lnp


netstat -s
 
Tcp:
    157755652 active connections openings
    202554221 passive connection openings
    75276041 failed connection attempts
    11611220 connection resets received
    1684 connections established
    10807524083 segments received
    11290888947 segments send out
    61151836 segments retransmited
    157 bad segments received.
    211666090 resets sent


netstat -anp|grep ":8070"
netstat -anlp|grep ":8070"
lsof -i :8070

网络接口信息
netstat -i
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
bond0            1500 9613696220      0    121 0      8685005758      0      0      0 BMmRU
cni0             1500 1484433200      0      0 0      1575872947      0      0      0 BMU
docker0          1500     4717      0      0 0           875      0      0      0 BMU
em1              1500 9613696221      0    121 0      8685005761      0      0      0 BMsRU
em2              1500        0      0      0 0             0      0      0      0 BMsU
em3              1500   107129      0      0 0             0      0      0      0 BMRU
em4              1500        0      0      0 0             0      0      0      0 BMU
flannel.1        1450 1534549191      0      0 0      1443518484      0   1258      0 BMRU
lo              65536 4191299456      0      0 0      4191299456      0      0      0 LRU

netstat -ie (同ifconfig)


TCP各种状态统计
netstat -nat |awk '{print $6}'|sort|uniq -c

排序 
netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn

分析access.log获得访问前10位的ip地址
awk '{print $1}' access.log |sort|uniq -c|sort -nr|head -10


查看连接某服务端口最多的IP地址
netstat -nat | grep "192.168.0.10:22" |awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -20

      

linux实用命令合集 linux运维常用命令 linux sort 命令

上一篇     下一篇
Linux系统监控工具大全

linux stress 工具简介

busybox编译

linux 帮助命令使用

kafka消息存储及索引机制

kafka消费机制要点