Tcpdump 常用命令

-n 以数字显示 -X 显示包体 -i 指定网卡 -w 写入文件 -c 包的个数

1. 指定端口

1
tcpdump -n -X -i any port 1234 -w 1.cap

2. 指定主机

1
tcpdump -n -X -i any host 192.168.0.101 -w 1.cap

3. 其他

1
2
3
4
5
6
7
8
# 监视指定主机和端口的数据包
tcpdump -i ens33 port 8080 and host node1

# 监视指定网络的数据包,如本机与192.168网段通信的数据包,"-c 10"表示只抓取10个包
tcpdump -i ens33 -c 10 net 192.168

# 抓取ping包
tcpdump -c 5 -nn -i eth0 icmp and src 192.168.100.62

3.参考

tcpdump说明

K8s 中的 Dns 问题

1. 检查本机的 dns 配置

1
2
3
4
5
6
7
8
9
# 建议不要配置 search,除非你自己明确, 可用的 dns 域名,如 8.8.8.8
# 修改后,centos系统不需要重启 NetworkManager, 重启可能被覆盖
cat /etc/resolv.conf

# 重启 kubelet
systemctl restart kubelet

# 重启 k8s pod
kubectl rollout restart deploy

2. 检查 pod 的 dns 配置

1
2
3
4
5
6
7
8
# 进入容器中
kubectl debug -it some-pod --image=busybox -- sh

# 在容器中查看 dns 配置, 这里一定要是 coredns 的 clusterIP, 如果不对,检查 kubelet 的 dns 配置
cat /etc/resolv.conf

# 在容器中查看 hosts 配置
cat /etc/hosts

3. 检查并配置 coredns 配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 检查配置
kubectl get cm coredns -n kube-system -oyaml

# 自定义配置,如添加 hosts 配置
kubectl apply -f - <<EOF
apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health {
           lameduck 5s
        }
        ready
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           fallthrough in-addr.arpa ip6.arpa
           ttl 30
        }
        prometheus :9153
        # 添加 hosts 配置
        hosts {
            172.16.1.36 git.abc.com
            fallthrough
        }
        # 不转发到 /etc/resolv.conf
        forward . 8.8.8.8
        cache 30
        loop
        reload
        loadbalance
    }
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
EOF

4. 问题现象

tektonpod dns 显示错误,重新设置主机的 /etc/resolv.conf, 重启 kubelet, 重启 tekton.

Ubuntu Add Static Ip

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# open target dir
cd /etc/netplan

# edit config file, you must creat if not exist
sudo vim 00-installer-config.yaml

# network device setting template
network:
  ethernets:
    ens33:
      #dhcp4: yes
      dhcp4: no
      addresses:
        - 192.168.130.129/24
      routes:
        - to: default
          via: 192.168.130.2

      #nameservers:
      #  addresses: [192.168.130.2]
  version: 2
  
# netplan apply 
sudo netplan apply

# restart 
reboot