github.com/mccv1r0/cni@v0.7.0-alpha1/cnitool/README.md (about)

     1  # cnitool
     2  
     3  `cnitool` is a simple program that executes a CNI configuration. It will
     4  add or remove an interface in an already-created network namespace.
     5  
     6  ## Example invocation
     7  First, install cnitool:
     8  
     9  ```
    10  go install github.com/containernetworking/cni/cnitool
    11  ```
    12  
    13  Then, check out and build the plugins. All commands should be run from this directory.
    14  ```
    15  git clone https://github.com/containernetworking/plugins.git
    16  cd plugins
    17  ./build.sh
    18  ```
    19  
    20  Create a network configuration
    21  ```
    22  echo '{"cniVersion":"0.3.1","name":"myptp","type":"ptp","ipMasq":true,"ipam":{"type":"host-local","subnet":"172.16.29.0/24","routes":[{"dst":"0.0.0.0/0"}]}}' | sudo tee /etc/cni/net.d/10-myptp.conf
    23  ```
    24  
    25  Create a network namespace. This will be called `testing`:
    26  
    27  ```
    28  sudo ip netns add testing
    29  ```
    30  
    31  Add the container to the network:
    32  ```
    33  sudo CNI_PATH=./bin cnitool add myptp /var/run/netns/testing
    34  ```
    35  
    36  Test that it works:
    37  ```
    38  sudo ip -n testing addr
    39  sudo ip netns exec testing ping -c 1 4.2.2.2
    40  ```
    41  
    42  And clean up:
    43  ```
    44  sudo CNI_PATH=./bin cnitool del myptp /var/run/netns/testing
    45  sudo ip netns del testing
    46  ```
    47