【tshark tcpdump】linux网络排查

抓包:

1、tcpdump

2、tshark是wireshark的命令行版。

tshark使用示例:

1,实时打印当前http请求的url

# tshark -s 512 -i eth0 -n -f 'tcp dst port 80' -R 'http.host and http.request.uri' -T fields -e http.host -e http.request.uri -l | tr -d '	'

参数含义:

    -s 512 :只抓取前512个字节数据
    -i eth0 :捕获eth0网卡
    -n :禁止网络对象名称解析
    -f 'tcp dst port 80' :只捕捉协议为tcp,目的端口为80的数据包
    -R 'http.host and http.request.uri' :过滤出http.host和http.request.uri
    -T fields -e http.host -e http.request.uri :打印http.host和http.request.uri
    -l :输出到标准输出

2、实时打印当前mysql查询语句

# tshark -s 512 -i eth0 -n -f 'tcp dst port 3306' -R 'mysql.query' -T fields -e mysql.query

参数含义:

    -s 512 :只抓取前512个字节数据
    -i eth0 :捕获eth0网卡
    -n :禁止网络对象名称解析
    -f 'tcp dst port 3306' :只捕捉协议为tcp,目的端口为3306的数据包
    -R 'mysql.query' :过滤出mysql.query
    -T fields -e mysql.query :打印mysql查询语句
tshark -f 'tcp dst port 6443'

3、查看网络流量 iftop

iftop,查看哪个进程占用带宽

原文地址:https://www.cnblogs.com/zealousness/p/11168278.html