github.com/baraj55/containernetworking-cni@v0.7.2-0.20200219164625-56ace59a9e7f/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  ## Environment Variables
     7  
     8  * `NETCONFPATH`: This environment variable needs to be set to a
     9    directory. It defaults to `/etc/cni/net.d`. The `cnitool` searches
    10    for CNI configuration files in this directory with the extension
    11    `*.conf` or `*.json`. It loads all the CNI configuration files in
    12    this directory and if it finds a CNI configuration with the `network
    13    name` given to the cnitool it returns the corresponding CNI
    14    configuration, else it returns `nil`.
    15  * `CNI_PATH`: For a given CNI configuration `cnitool` will search for
    16    the corresponding CNI plugin in this path.
    17  
    18  ## Example invocation
    19  
    20  First, install cnitool:
    21  
    22  ```bash
    23  go get github.com/containernetworking/cni
    24  go install github.com/containernetworking/cni/cnitool
    25  ```
    26  
    27  Then, check out and build the plugins. All commands should be run from this directory.
    28  
    29  ```bash
    30  git clone https://github.com/containernetworking/plugins.git
    31  cd plugins
    32  ./build_linux.sh
    33  # or
    34  ./build_windows.sh
    35  ```
    36  
    37  Create a network configuration
    38  
    39  ```bash
    40  echo '{"cniVersion":"0.4.0","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
    41  ```
    42  
    43  Create a network namespace. This will be called `testing`:
    44  
    45  ```bash
    46  sudo ip netns add testing
    47  ```
    48  
    49  Add the container to the network:
    50  
    51  ```bash
    52  sudo CNI_PATH=./bin cnitool add myptp /var/run/netns/testing
    53  ```
    54  
    55  Check whether the container's networking is as expected (ONLY for spec v0.4.0+):
    56  
    57  ```bash
    58  sudo CNI_PATH=./bin cnitool check myptp /var/run/netns/testing
    59  ```
    60  
    61  Test that it works:
    62  
    63  ```bash
    64  sudo ip -n testing addr
    65  sudo ip netns exec testing ping -c 1 4.2.2.2
    66  ```
    67  
    68  And clean up:
    69  
    70  ```bash
    71  sudo CNI_PATH=./bin cnitool del myptp /var/run/netns/testing
    72  sudo ip netns del testing
    73  ```