Skip to content

Commit

Permalink
Add tcpdump
Browse files Browse the repository at this point in the history
  • Loading branch information
shfshanyue committed Nov 14, 2019
1 parent 6dde91a commit 95afbd1
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@
1. 监控
1. [linux 各项监控指标](https://github.com/shfshanyue/op-note/blob/master/linux-monitor.md) · [(掘金)](https://juejin.im/post/5dae57fbf265da5b5b6c7881)
1. [linux 监控与报警]() - TODO
1. 高频 linux 命令
1. 高频 linux 命令关键选项及示例
1. [sed](https://github.com/shfshanyue/op-note/blob/master/linux-sed.md) · [(掘金)](https://juejin.im/post/5db1053df265da4d57770c30)
1. [awk](https://github.com/shfshanyue/op-note/blob/master/linux-awk.md)
1. [jq](https://github.com/shfshanyue/op-note/blob/master/jq.md) · [(掘金)](https://juejin.im/post/5db104f7f265da4d2e121510)
1. [iptables](https://github.com/shfshanyue/op-note/blob/master/iptables.md)
1. [tcpdump](https://github.com/shfshanyue/op-note/blob/master/linux-tcpdump.md)
1. [htop](https://github.com/shfshanyue/op-note/blob/master/htop.md)

## 00 如果没有服务器 · PaaS
Expand Down
2 changes: 1 addition & 1 deletion linux-awk.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: awk 命令详解
title: awk 命令使用及示例

---

Expand Down
6 changes: 3 additions & 3 deletions linux-sed.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: sed 命令使用及示例
title: sed 命令详解及示例
keywords: sed examples,mac中的sed,sed删除文件,sed替换文件
description: sed 是一个用来筛选与转换文本内容的工具。一般用来批量替换,删除某行文件。如果想在 mac 中使用 sed,请使用 gsed 代替,不然会被坑
date: 2019-10-18 22:00
Expand All @@ -9,7 +9,7 @@ tags:

---

# sed 命令使用及示例
# sed 命令详解及示例

`sed` 是一个用来筛选与转换文本内容的工具。一般用来批量替换,删除某行文件

Expand All @@ -36,7 +36,7 @@ $ sed -n '3,5p' file
$ sed -i '2d' file
```

### 选项
### 关键选项

+ `-n`: 打印匹配内容行
+ `-i`: 直接替换文本内容
Expand Down
89 changes: 89 additions & 0 deletions linux-tcpdump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: tcpdump 命令详解及示例
keywords: tcpdump,linux抓包
description: sed 是一个用来筛选与转换文本内容的工具。一般用来批量替换,删除某行文件。如果想在 mac 中使用 sed,请使用 gsed 代替,不然会被坑
date: 2019-11-14 20:00
sidebarDepth: 3
tags:
- linux

---

# tcpdump 命令详解及示例

Q: `tcpdump` 是干吗的\
A: 抓包的\
Q: 除了 `tcpdump` 还有啥能抓包\
A: `wireshark`\
Q: 为啥不讲 `wireshark` 抓包\
A: `wireshark` 在 linux 上不能用\

<!--more-->

+ 原文链接: [tcpdump 命令详解及示例](https://github.com/shfshanyue/op-note/blob/master/linux-tcpdump.md)
+ 系列文章: [当我有台服务器时我做了什么](https://github.com/shfshanyue/op-note)

## tcpdump 命令详解

### 关键选项

+ `-c count`: 指定打印条数
+ `-i interface`: 指定网络接口,如常见的 `eth0``lo`,可以通过 `ifconfig` 打印所有网络接口
+ `-vv`: 尽可能多地打印信息

### 过滤器

过滤器,顾名思义,过滤一部分数据包,**而过滤器使用 `pcap-filter` 的语法**

所以你可以查看 `pcap-filter` 手册

``` bash
# 查看所有过滤器
$ man pcap-fliter
```

过滤器可以简单分为三类

+ `type`: 有四种类型 `host``net``port``portrange`
+ `tcpdump port 22`
+ `tcpdump port ssh`
+ `dir`: 源地址和目标地址,主要有 `src``dst`
+ `tcpdump src port ssh`
+ `proto`: 协议,有 `ip``arp``rarp``tcp``udp``icmp`
+ `tcpdump icmp`

## tcpdump examples

+ 命令: `netstat -i`\
解释: 打印所有网络接口

+ 命令: `tcpdump -i eth0`\
解释: 监视网络接口 `eth0` 的数据包

+ 命令: `tcpdump host 172.18.0.10`\
解释: 监视主机地址 `172.18.0.10` 的数据包

+ 命令: `tcpdump net 172.18.0.1/24`\
解释: 监视网络 `172.10.0.1/24` 的所有数据包

+ 命令: `tcpdump tcp port 443`\
解释: 监听 https 请求

+ 命令: `tcpdump tcp port 443 and host 172.18.0.10`\
解释: 监听目标地址或源地址是 172.18.0.10 的 https 请求

+ 命令: `tcpdump icmp`\
解释: 监听 ICMP 协议 (比如典型的 PING 命令)

+ 命令: `tcpdump arp`\
解释: 监听 ARP 协议

+ 命令: `tcpdump 'tcp[tcpflags] == tcp-syn'`\
解释: 监听 TCP 协议中 `flag``SYN` 的,可以用来监听三次握手

+ 命令: `tcpdump -vv tcp port 80 | grep 'Host:'`\
解释: 找到 http 中所有的 Host

## 相关文章

+ [A tcpdump Tutorial with Examples — 50 Ways to Isolate Traffic](https://danielmiessler.com/study/tcpdump/)

0 comments on commit 95afbd1

Please sign in to comment.