Skip to content

Instantly share code, notes, and snippets.

@mrjk
Created January 19, 2023 05:09
Show Gist options
  • Save mrjk/6e1c46ee384b7066d9a34dba1f3b3877 to your computer and use it in GitHub Desktop.
Save mrjk/6e1c46ee384b7066d9a34dba1f3b3877 to your computer and use it in GitHub Desktop.
How to tcpdump a docker container interface from host?

How to find which container map on the host

$ docker exec -ti $container cut -d: -f1 /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo
  eth0
  eth1
  eth2
  eth3

Find the interfaces number of the interface:

$ docker exec -ti $container  cat /sys/class/net/eth0/iflink
261271

And it's mapping on the host:

$ ip link | grep 261271
261271: vethb8909c1@if261270: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-ab13d66842d0 state UP mode DEFAULT group default 

To tcpdump on it:

tcpdump -i veth9ab211d -vnn  icmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment