docker容器抓包

 

1.获取容器id和name

[root@localhost ~]# docker ps |grep milvus-standalone
8985d21b3779   milvusdb/milvus:v2.4.23                                         "/tini -- milvus run…"   2 days ago   Up 47 hours (healthy)   0.0.0.0:9091->9091/tcp, :::9091->9091/tcp, 0.0.0.0:19530->19530/tcp, :::19530->19530/tcp   milvus-standalone
[root@localhost ~]# 

 

2.找到容器运行对应的宿主机上的进程pid

[root@localhost ~]# docker inspect --format "{{.State.Pid}}" 8985d21b3779
18079

 

3.使用nsenter切换网络命名空间

可在切换前后执行ifconfig来对比变化

切换前

[root@localhost ~]# ifconfig -a
br-00a5a504046d: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.0.1  netmask 255.255.0.0  broadcast 172.20.255.255
        inet6 fe80::42:66ff:fee3:42b6  prefixlen 64  scopeid 0x20<link>
        ether 02:42:66:e3:42:b6  txqueuelen 0  (Ethernet)
        RX packets 103  bytes 10798 (10.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 99  bytes 63736 (62.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br-1829dfc2f707: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.16.1  netmask 255.255.240.0  broadcast 192.168.31.255
        inet6 fe80::42:5fff:fe30:bcc0  prefixlen 64  scopeid 0x20<link>
        ether 02:42:5f:30:bc:c0  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

br-3f60cd91c3f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.21.0.1  netmask 255.255.0.0  broadcast 172.21.255.255
        inet6 fe80::42:1fff:fe45:8ed4  prefixlen 64  scopeid 0x20<link>
        ether 02:42:1f:45:8e:d4  txqueuelen 0  (Ethernet)
        RX packets 1069464788  bytes 1194212079391 (1.0 TiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1069464788  bytes 1194212079391 (1.0 TiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
        inet6 fe80::42:8fff:feeb:f795  prefixlen 64  scopeid 0x20<link>
        ether 02:42:8f:eb:f7:95  txqueuelen 0  (Ethernet)
        RX packets 175016508  bytes 21298907190 (19.8 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 136669395  bytes 474097345827 (441.5 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.134  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::5054:ff:fec8:dc1f  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:c8:dc:1f  txqueuelen 1000  (Ethernet)
        RX packets 3265848654  bytes 2406227313571 (2.1 TiB)
        RX errors 0  dropped 17454076  overruns 0  frame 0
        TX packets 1321360343  bytes 570156963466 (531.0 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1069464788  bytes 1194212079391 (1.0 TiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1069464788  bytes 1194212079391 (1.0 TiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth00398a1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::1465:7eff:fe48:7c06  prefixlen 64  scopeid 0x20<link>
        ether 16:65:7e:48:7c:06  txqueuelen 0  (Ethernet)
        RX packets 583023  bytes 53108914 (50.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 390109  bytes 44390332 (42.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth0f57eb2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::5429:11ff:fe90:5fe6  prefixlen 64  scopeid 0x20<link>
        ether 56:29:11:90:5f:e6  txqueuelen 0  (Ethernet)
        RX packets 103  bytes 10798 (10.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 99  bytes 63736 (62.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth3766d1f: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::ec32:a8ff:fe14:f41e  prefixlen 64  scopeid 0x20<link>
        ether ee:32:a8:14:f4:1e  txqueuelen 0  (Ethernet)
        RX packets 27154  bytes 1722034 (1.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 20715  bytes 1362096 (1.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth5195ea3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::b8b4:4cff:fe71:efbc  prefixlen 64  scopeid 0x20<link>
        ether ba:b4:4c:71:ef:bc  txqueuelen 0  (Ethernet)
        RX packets 130122  bytes 9146910 (8.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 94428  bytes 6921238 (6.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

veth6a6f86c: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::7ca3:9fff:fef1:d79e  prefixlen 64  scopeid 0x20<link>
        ether 7e:a3:9f:f1:d7:9e  txqueuelen 0  (Ethernet)
        RX packets 482  bytes 70489 (68.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 491  bytes 68160 (66.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethc41d17a: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::50e1:5cff:fe7d:ce36  prefixlen 64  scopeid 0x20<link>
        ether 52:e1:5c:7d:ce:36  txqueuelen 0  (Ethernet)
        RX packets 39845  bytes 3429759 (3.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 79561  bytes 5733636 (5.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethecaa8d8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::f002:82ff:fed8:a695  prefixlen 64  scopeid 0x20<link>
        ether f2:02:82:d8:a6:95  txqueuelen 0  (Ethernet)
        RX packets 19079  bytes 1286509 (1.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15888  bytes 1178766 (1.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethf196052: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::8091:53ff:fe38:4f9e  prefixlen 64  scopeid 0x20<link>
        ether 82:91:53:38:4f:9e  txqueuelen 0  (Ethernet)
        RX packets 57  bytes 54135 (52.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 75  bytes 7656 (7.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vethfb23015: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::48e6:48ff:fea1:874f  prefixlen 64  scopeid 0x20<link>
        ether 4a:e6:48:a1:87:4f  txqueuelen 0  (Ethernet)
        RX packets 345622  bytes 41478583 (39.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 541120  bytes 50402738 (48.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

切换后
[root@localhost ~]# nsenter -n -t 18079

 

[root@localhost ~]# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.21.0.4  netmask 255.255.0.0  broadcast 172.21.255.255
        ether 02:42:ac:15:00:04  txqueuelen 0  (Ethernet)
        RX packets 390216  bytes 44402865 (42.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 583189  bytes 53124125 (50.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 19060275  bytes 2191208915 (2.0 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19060275  bytes 2191208915 (2.0 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

4.然后执行抓包
tcpdump -i any -w /tmp/pod.pcap

 

5.退出容器网络空间

[root@localhost ~]# exit
logout

posted @ 2025-07-24 09:45  slnngk  阅读(28)  评论(0)    收藏  举报