github.com/inspektor-gadget/inspektor-gadget@v0.28.1/docs/builtin-gadgets/trace/network.md (about)

     1  ---
     2  title: 'Using trace network'
     3  weight: 10
     4  ---
     5  
     6  The network gadget monitors the network activity in the specified pods
     7  and records the list of TCP connections and UDP streams.
     8  
     9  ### On Kubernetes
    10  
    11  * Start the gadget:
    12  ```bash
    13  $ kubectl gadget trace network -n demo
    14  ```
    15  
    16  * Generate some network traffic:
    17  ```bash
    18  $ kubectl run -ti -n demo --image=busybox --restart=Never shell -- wget 1.1.1.1.nip.io
    19  ```
    20  
    21  * Observe the results:
    22  ```
    23  K8S.NODE         K8S.NAMESPACE    K8S.POD                        TYPE      PROTO  PORT    REMOTE
    24  minikube         demo             shell                          OUTGOING  UDP    53      svc kube-system/kube-dns
    25  minikube         demo             shell                          OUTGOING  TCP    80      endpoint 1.1.1.1
    26  ```
    27  
    28  ### With `ig`
    29  
    30  Let's start the gadget in a terminal:
    31  
    32  ```bash
    33  $ sudo ig trace network -c test-container
    34  RUNTIME.CONTAINERNAME           TYPE      PROTO PORT  REMOTE
    35  ```
    36  
    37  Run a container that generates TCP and UDP network traffic:
    38  
    39  ```bash
    40  $ docker run --name test-container -ti --rm busybox /bin/sh -c "wget http://1.1.1.1.nip.io/"
    41  ```
    42  
    43  The tools will show the network activity:
    44  
    45  ```bash
    46  $ sudo ig trace network -c test-container
    47  RUNTIME.CONTAINERNAME           TYPE      PROTO PORT  REMOTE
    48  demo                            OUTGOING  UDP   53    192.168.67.1
    49  demo                            OUTGOING  TCP   80    1.1.1.1
    50  ```