Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
title description date draft toc weight

cnitool is a simple program that executes a CNI configuration. It will add or remove an interface in an already-created network namespace.

Environment Variables

  • NETCONFPATH: This environment variable needs to be set to a directory. It defaults to /etc/cni/net.d. The cnitool searches for CNI configuration files in this directory with the extension *.conf or *.json. It loads all the CNI configuration files in this directory and if it finds a CNI configuration with the network name given to the cnitool it returns the corresponding CNI configuration, else it returns nil.
  • CNI_PATH: For a given CNI configuration cnitool will search for the corresponding CNI plugin in this path.

Example invocation

First, install cnitool:

go get
go install

Then, check out and build the plugins. All commands should be run from this directory.

git clone
cd plugins
# or

Create a network configuration

echo '{"cniVersion":"0.4.0","name":"myptp","type":"ptp","ipMasq":true,"ipam":{"type":"host-local","subnet":"","routes":[{"dst":""}]}}' | sudo tee /etc/cni/net.d/10-myptp.conf

Create a network namespace. This will be called testing:

sudo ip netns add testing

Add the container to the network:

sudo CNI_PATH=./bin cnitool add myptp /var/run/netns/testing

Check whether the container's networking is as expected (ONLY for spec v0.4.0+):

sudo CNI_PATH=./bin cnitool check myptp /var/run/netns/testing

Test that it works:

sudo ip -n testing addr
sudo ip netns exec testing ping -c 1

And clean up:

sudo CNI_PATH=./bin cnitool del myptp /var/run/netns/testing
sudo ip netns del testing