PageSourceSearch

https://www.cni.dev/docs/cnitool/

html cni.dev collected 2026-10-01 11:25:19 UTC 8,283 bytes, 27 lines download raw bytes

1<!doctype html><html><head><title>CNI</title><link rel=stylesheet href=/css/style.4f4e0706c022dab552094185097fc886f7225b493627d4c27d6ce3f8537d3fc4.css integrity="sha256-T04HBsAi2rVSCUGFCX/IhvciW0k2J9TCfWzj+FN9P8Q="><link rel="shortcut icon" href=/favicon.png></head><body><div class="navbar navbar-expand-lg navbar-light bg-light sticky-top" role=navigation aria-label="main navigation"><div class=container><div class=navbar-brand><a class=navbar-item href=https://www.cni.dev/><img src=/img/logos/cni-horizontal-color.png class=logo></a></div><button class=navbar-toggler type=button data-toggle=collapse data-target=#main-nav aria-controls=main-nav aria-expanded=false aria-label="Toggle navigation">
2<span class=navbar-toggler-icon></span></button><div class="collapse navbar-collapse" id=main-nav><ul class="navbar-nav mr-auto"><li class="navbar-start navbar-item"><a class=nav-link href=/>Home</a><li class="navbar-start navbar-item"><a class=nav-link href=/docs/>Documentation</a><li class="navbar-start navbar-item"><a class=nav-link href=/plugins/current/>Plugins</a></li></ul><ul class="navbar-nav float-right"><li class=navbar-item><a class="btn text-light" style=background-color:#000 href=https://github.com/containernetworking><span class=icon><i class="fab fa-github">&nbsp;</i></span>
3GitHub</a></li></ul></div></div></div><main><header><div><div class="container mt-4 mb-4 pb-2 border-bottom"><section class=row><div class="col col-8 breadcrumb" aria-label=breadcrumbs><ul class="mb-0 pt-2" style=vertical-align:middle><li>/ <a href=/>Home</a></li><li>/ <a href=/docs/>CNI</a></li><li class=is-active>/ <a href=/docs/cnitool/><code>cnitool</code></a></li></ul></div><div class="col col-4"><a href=https://github.com/containernetworking/cni.dev/blob/main/content/docs/cnitool.md class="btn btn-primary" target=_blank><span class="fas fa-pen"></span>&nbsp; Edit on GitHub</a></div></section></div></div></header><div class=container><section class=row><section class="col col-4"><nav class=section-nav><p class=menu-label>CNI Documentation:</p><ul class=menu-list><li><a href=/docs/>CNI</a><ul><li><a href=/docs/spec/>Specification</a></li></ul><ul><li><a href=/docs/conventions/>Conventions</a></li></ul><ul><li><a href=/docs/cnitool/><code>cnitool</code></a></li></ul><ul><li><a href=/docs/spec-upgrades/>CNI spec versions</a></li></ul><ul><li><a href=/docs/code-of-conduct/>Community Code of Conduct</a></li></ul><ul><li><a href=/docs/contributing/>Contributing</a></li></ul><ul><li><a href=/docs/dco/>DCO</a></li></ul><ul><li><a href=/docs/governance/>Governance</a></li></ul><ul><li><a href=/docs/roadmap/>Roadmap</a></li></ul><ul><li><a href=/docs/owners/>CNI Maintainers</a></li></ul></li></nav><hr><p>On this page:</p><nav id=TableOfContents><ul><li><a href=#environment-variables>Environment Variables</a></li><li><a href=#example-invocation>Example invocation</a></li></ul></nav></section><section class="col col-8"><h1 class=title><code>cnitool</code></h1><p class=subtitle>README.md</p><div class=content><p><code>cnitool</code> is a simple program that executes a CNI configuration. It will
4add or remove an interface in an already-created network namespace.</p><h2 id=environment-variables>Environment Variables
5<a href=#environment-variables><span class="icon hashlink"><i class="fas fa-link"></i></span></a></h2><ul><li><code>NETCONFPATH</code>: This environment variable needs to be set to a
6directory. It defaults to <code>/etc/cni/net.d</code>. The <code>cnitool</code> searches
7for CNI configuration files in this directory with the extension
8<code>*.conf</code> or <code>*.json</code>. It loads all the CNI configuration files in
9this directory and if it finds a CNI configuration with the <code>network name</code> given to the cnitool it returns the corresponding CNI
10configuration, else it returns <code>nil</code>.</li><li><code>CNI_PATH</code>: For a given CNI configuration <code>cnitool</code> will search for
11the corresponding CNI plugin in this path.</li></ul><h2 id=example-invocation>Example invocation
12<a href=#example-invocation><span class="icon hashlink"><i class="fas fa-link"></i></span></a></h2><p>First, install cnitool:</p><div class=highlight><pre style=color:#e7e9db;background-color:#2f1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-bash data-lang=bash>go get github.com/containernetworking/cni
13go install github.com/containernetworking/cni/cnitool
14</code></pre></div><p>Then, check out and build the plugins. All commands should be run from this directory.</p><div class=highlight><pre style=color:#e7e9db;background-color:#2f1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-bash data-lang=bash>git clone https://github.com/containernetworking/plugins.git
15cd plugins
16./build_linux.sh
17<span style=color:#776e71># or</span>
18./build_windows.sh
19</code></pre></div><p>Create a network configuration</p><div class=highlight><pre style=color:#e7e9db;background-color:#2f1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-bash data-lang=bash>echo <span style=color:#48b685>&#39;{&#34;cniVersion&#34;:&#34;0.4.0&#34;,&#34;name&#34;:&#34;myptp&#34;,&#34;type&#34;:&#34;ptp&#34;,&#34;ipMasq&#34;:true,&#34;ipam&#34;:{&#34;type&#34;:&#34;host-local&#34;,&#34;subnet&#34;:&#34;172.16.29.0/24&#34;,&#34;routes&#34;:[{&#34;dst&#34;:&#34;0.0.0.0/0&#34;}]}}&#39;</span> | sudo tee /etc/cni/net.d/10-myptp.conf
20</code></pre></div><p>Create a network namespace. This will be called <code>testing</code>:</p><div class=highlight><pre style=color:#e7e9db;background-color:#2f1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-bash data-lang=bash>sudo ip netns add testing
21</code></pre></div><p>Add the container to the network:</p><div class=highlight><pre style=color:#e7e9db;background-color:#2f1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-bash data-lang=bash>sudo <span style=color:#ef6155>CNI_PATH</span><span style=color:#5bc4bf>=</span>./bin cnitool add myptp /var/run/netns/testing
22</code></pre></div><p>Check whether the container&rsquo;s networking is as expected (ONLY for spec v0.4.0+):</p><div class=highlight><pre style=color:#e7e9db;background-color:#2f1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-bash data-lang=bash>sudo <span style=color:#ef6155>CNI_PATH</span><span style=color:#5bc4bf>=</span>./bin cnitool check myptp /var/run/netns/testing
23</code></pre></div><p>Test that it works:</p><div class=highlight><pre style=color:#e7e9db;background-color:#2f1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-bash data-lang=bash>sudo ip -n testing addr
24sudo ip netns exec testing ping -c <span style=color:#f99b15>1</span> 4.2.2.2
25</code></pre></div><p>And clean up:</p><div class=highlight><pre style=color:#e7e9db;background-color:#2f1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-bash data-lang=bash>sudo <span style=color:#ef6155>CNI_PATH</span><span style=color:#5bc4bf>=</span>./bin cnitool del myptp /var/run/netns/testing
26sudo ip netns del testing
27</code></pre></div></div></section></section></div></main><footer class=footer><div class=container></br><p>&copy; 2026 The CNI Authors | Documentation Distributed under CC-BY-4.0</br>&copy; 2026 The Linux Foundation. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our <a href=https://www.linuxfoundation.org/trademark-usage/>Trademark Usage</a> page.</p></div></footer>
27<script src=https://code.jquery.com/jquery-3.5.1.slim.min.js integrity=sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj crossorigin=anonymous></script>
27<script src=https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js integrity=sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN crossorigin=anonymous></script>
27<script src=https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js integrity=sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV crossorigin=anonymous></script>
27<script src=/js/app.bd80924e99112063d11e41773f8fa43d81228313f734f4af89371f31e884dcd2.js type=module integrity="sha256-vYCSTpkRIGPRHkF3P4+kPYEigxP3NPSviTcfMeiE3NI="></script>
27</body></html>

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.