[命令] Linux 命令 tcpdump (网络抓包)

内容一:tcpdump 命令格式

# tcpdump <option> <proto> <dir> <type>

内容二:tcpdump 命令选项 (option)

1) -A use ASCII print all data, it is convenient for read website date.
2) -c <number>, number of packet captures
3) -C <file size>,size of file
4) -e, display data link layer
5) -G <second>, create a new file after these seconds 
6) -l, send the output to next command, example: tcpdump -i eth0 -s0 | grep 'Server:'
7) -n, do not resolve domain only display IP address
8) -nn, do not resolve domain and port only display IP address
9) -i <interface>, such as internet card and can use: -i any
10) -p, only display the data which point it self
11) -r <file>, read data from file 
12) -s <snaplen>, size of length of the network package and can use: -s 0 to ulimite the length, the default value is 96B
13) -v , display detail
14) -vv, display detail more than -v
15) -vvv, display detail more than -vv
16) -w <file>, write the output result into a file
17) -W <number>, how many files will output result into

内容三:tcpdump 命令协议 (proto)

1) tcp or proto 6
2) udp or proto 17
3) icmp, example: proto \\icmp is icmp
4) ip
5) ip6
6) arp
7) rarp
8) ether
9) wlan

内容四:tcpdump 命令方向 (dir)

1) src
2) dst

内容五:tcpdump 命令种类 (type)

1) host <IP address>
2) net <network segment>, example: 10 is 10.x.x.x/8 , 192.168.0 is 192.168.0.0/24
3) port <port>
4) portrange <port range>

内容六:tcpdump 命令逻辑

1) and or &&
2) or or ||
3) not or !

内容七:tcpdump 命令的使用案例

7.1 显示发送到某个 IP 地址的某个端口的网络数据包

# tcpdump -i any dst 192.168.0.1 and udp port 514

(补充:这里以显示发送到 IP 地址 192.168.0.1 的 UDP 514 端口为例,如果有这类网络数据包的话则详细信息会在命令输出后显示出来)

7.2 显示从某个 IP 地址发送来的网络数据包

# tcpdump -vv src host 192.168.0.1

(补充:这里以显示从 IP 地址 192.168.0.1 发送来的网络数据包为例,如果有这类网络数据包的话则详细信息会在命令输出后显示出来)

7.3 将所有抓到的网络数据包导入到某个文件里

# tcpdump -i any -w /tmp/telnet.cap

(补充:这里以将所有抓到的数据包导出到文件 /tmp/telnet.cap 为例)

7.4 将某个网卡抓到的网络数据包导入到某个文件里

# tcpdump -i eth0 -s 0 -w /tmp/$(hostname)-$(date +"%Y-%m-%d-%H-%M-%S").pcap host 192.168.1.1 or host 192.168.1.2

(补充:这里以将网卡 eth0 网卡上抓到的来源或目的是 192.168.1.1 或 192.168.1.2 的数据包导出到文件 /tmp/$(hostname)-$(date +”%Y-%m-%d-%H-%M-%S”).pcap 为例)

[内容] 全球公共免费 DNS

AdGuard

94.140.14.14
94.140.14.15
94.140.15.15
94.140.15.16

Cloudflare

1.0.0.1
1.0.0.2
1.0.0.3
1.1.1.1
1.1.1.2
1.1.1.3

COMODO

8.20.247.20
8.26.56.26

DNS Watch

84.200.69.80
84.200.70.40

Dyn

216.146.35.35
216.146.36.36

Level 3

209.244.0.3
209.244.0.4

Neustar

156.154.70.1
156.154.71.1

FreeDNS

37.235.1.174
37.235.1.177

Google

8.8.4.4
8.8.8.8

OpenDNS

208.67.220.220
208.67.222.222

SAFEDNS

195.46.39.39
195.46.39.40

Symantec

199.85.126.10
199.85.137.10