Files
clear-linux-documentation/guides/network/assign-static-ip.html
2024-11-04 18:56:31 +00:00

280 lines
16 KiB
HTML

<!DOCTYPE html>
<html lang="en" data-content_root="../../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Assign a static IP address &#8212; Documentation for Clear Linux* project</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/bizstyle.css?v=5283bb3d" />
<link rel="stylesheet" type="text/css" href="../../_static/copybutton.css?v=76b2166b" />
<script src="../../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../../_static/doctools.js?v=9bcbadda"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/clipboard.min.js?v=a7894cd8"></script>
<script src="../../_static/copybutton.js?v=a56c686a"></script>
<script src="../../_static/bizstyle.js"></script>
<link rel="canonical" href="https://clearlinux.github.io/clear-linux-documentation/guides/network/assign-static-ip.html" />
<link rel="icon" href="../../_static/favicon.ico"/>
<link rel="author" title="About these documents" href="../../about.html" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Use DPDK to send packets between platforms" href="dpdk.html" />
<link rel="prev" title="Validate signatures" href="../maintenance/validate-signatures.html" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<!--[if lt IE 9]>
<script src="_static/css3-mediaqueries.js"></script>
<![endif]-->
</head><body>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="dpdk.html" title="Use DPDK to send packets between platforms"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="../maintenance/validate-signatures.html" title="Validate signatures"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../index.html">Documentation for Clear Linux* project</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Guides</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Assign a static IP address</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="assign-a-static-ip-address">
<span id="assign-static-ip"></span><h1>Assign a static IP address<a class="headerlink" href="#assign-a-static-ip-address" title="Link to this heading"></a></h1>
<p>This guide explains how to assign a static IP address. This may be helpful in
scenarios such as a network with no DHCP server.</p>
<nav class="contents local" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#identify-which-program-is-managing-the-interface" id="id1">Identify which program is managing the interface</a></p></li>
<li><p><a class="reference internal" href="#using-networkmanager" id="id2">Using NetworkManager</a></p></li>
<li><p><a class="reference internal" href="#using-systemd-networkd" id="id3">Using systemd-networkd</a></p></li>
</ul>
</nav>
<section id="identify-which-program-is-managing-the-interface">
<h2><a class="toc-backref" href="#id1" role="doc-backlink">Identify which program is managing the interface</a><a class="headerlink" href="#identify-which-program-is-managing-the-interface" title="Link to this heading"></a></h2>
<p>New installations of Clear Linux* OS use NetworkManager as the default network
interface manager for all network connections.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ul class="simple">
<li><p>The cloud Clear Linux OS images continue to use <cite>systemd-networkd</cite> to manage
network connections.</p></li>
<li><p>In earlier Clear Linux OS versions, <cite>systemd-network</cite> was used to manage Ethernet
interfaces and NetworkManager was used for wireless interfaces.</p></li>
</ul>
</div>
<p>Before defining a configuration for assigning a static IP address, verify
which program is managing the network interface.</p>
<ol class="arabic">
<li><p>Check the output of <strong class="command">nmcli device</strong> to see if NetworkManager is
managing the device.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>nmcli<span class="w"> </span>device<span class="w"> </span>status
</pre></div>
</div>
<p>If the STATE column for the device shows <em>connected</em> or <em>disconnected</em>, the
network configuration is being managed by NetworkManager, then use the
instructions for <a class="reference internal" href="#nm-static-ip"><span class="std std-ref">using NetworkManager</span></a>.</p>
<p>If the STATE column for the device shows <em>unmanaged</em>, then check if the
device is being managed by systemd-networkd.</p>
</li>
<li><p>Check the output of <strong class="command">networkctl list</strong> to see if
<cite>systemd-networkd</cite> is managing the device.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>networkctl<span class="w"> </span>list
</pre></div>
</div>
<p>If the SETUP column for the device shows <em>configured</em>, the network
configuration is being managed by <cite>systemd-networkd</cite>, then use the
instructions for <a class="reference internal" href="#networkd-static-ip"><span class="std std-ref">using systemd-networkd</span></a>.</p>
</li>
</ol>
</section>
<section id="using-networkmanager">
<span id="nm-static-ip"></span><h2><a class="toc-backref" href="#id2" role="doc-backlink">Using NetworkManager</a><a class="headerlink" href="#using-networkmanager" title="Link to this heading"></a></h2>
<p>Network connections managed by NetworkManager are stored as files with the
<code class="file docutils literal notranslate"><span class="pre">.nmconnection</span></code> file extension in the
<code class="file docutils literal notranslate"><span class="pre">/etc/NetworkManager/system-connections/</span></code> directory.</p>
<p>A few tools exists to aid to manipulate network connections managed by
NetworkManager:</p>
<ul class="simple">
<li><p>nmcli - a command-line tool</p></li>
<li><p>nmtui - a text user interface that provides a pseudo graphical menu in the
terminal</p></li>
<li><p>nm-connection-editor - a graphical user interface</p></li>
</ul>
<p>The method below uses the command line tool nmcli to modify network
connection.</p>
<ol class="arabic">
<li><p>Identify the existing connection name:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>nmcli<span class="w"> </span>connection<span class="w"> </span>show
</pre></div>
</div>
<p>Sample output:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>NAME<span class="w"> </span>UUID<span class="w"> </span>TYPE<span class="w"> </span>DEVICE
Wired<span class="w"> </span>connection<span class="w"> </span><span class="m">1</span><span class="w"> </span><span class="m">00000000</span>-0000-0000-0000-000000000000<span class="w"> </span><span class="m">802</span>-3-etherneten01
</pre></div>
</div>
<p>If a connection does not exist, create it with the
<strong class="command">nmcli connection add</strong> command.</p>
</li>
<li><p>Modify the connection to use a static IP address. Replace the variables in
brackets with the appropriate values. Replace <em>[CONNECTION_NAME]</em> with the
NAME from the command above.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sudo</span> <span class="n">nmcli</span> <span class="n">connection</span> <span class="n">modify</span> <span class="s2">&quot;[CONNECTION_NAME]&quot;</span> \
<span class="n">ipv4</span><span class="o">.</span><span class="n">method</span> <span class="s2">&quot;manual&quot;</span> \
<span class="n">ipv4</span><span class="o">.</span><span class="n">addresses</span> <span class="s2">&quot;[IP_ADDRESS]/[CIDR_NETMASK]&quot;</span> \
<span class="n">ipv4</span><span class="o">.</span><span class="n">gateway</span> <span class="s2">&quot;[GATEWAY_IP_ADDRESS]&quot;</span> \
<span class="n">ipv4</span><span class="o">.</span><span class="n">dns</span> <span class="s2">&quot;[PRIMARY_DNS_IP],[SECONDARY_DNS_IP]&quot;</span>
</pre></div>
</div>
<p>See the <a class="reference external" href="https://developer.gnome.org/NetworkManager/stable/nmcli.html">nmcli developer page</a> for more
configuration options. For advanced configurations, the
<code class="file docutils literal notranslate"><span class="pre">/etc/NetworkManager/system-connections/*.nmconnection</span></code>. can be edited
directly.</p>
</li>
<li><p>Restart the NetworkManager server to reload the DNS servers:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>systemctl<span class="w"> </span>restart<span class="w"> </span>NetworkManager
</pre></div>
</div>
</li>
<li><p>Verify your static IP address details have been set:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>nmcli
</pre></div>
</div>
</li>
</ol>
</section>
<section id="using-systemd-networkd">
<span id="networkd-static-ip"></span><h2><a class="toc-backref" href="#id3" role="doc-backlink">Using systemd-networkd</a><a class="headerlink" href="#using-systemd-networkd" title="Link to this heading"></a></h2>
<p>Network connections managed by systemd-networkd are stored as files with the
<code class="file docutils literal notranslate"><span class="pre">.network</span></code> file extension the <code class="file docutils literal notranslate"><span class="pre">/etc/systemd/network/</span></code> directory.</p>
<p>Files to manipulate network connections managed by systemd-networkd must be
created manually.</p>
<ol class="arabic">
<li><p>Create the <code class="file docutils literal notranslate"><span class="pre">/etc/systemd/network</span></code> directory if it does not already exist:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>mkdir<span class="w"> </span>-p<span class="w"> </span>/etc/systemd/network
</pre></div>
</div>
</li>
<li><p>Create a <code class="file docutils literal notranslate"><span class="pre">.network</span></code> file and add the following content. Replace the
variables in brackets with the appropriate values. Replace <em>[INTERFACE_NAME]</em>
with LINK from the output of the <strong class="command">networkctl list</strong> command that was
run previously.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span><span class="nv">$EDITOR</span><span class="w"> </span>/etc/systemd/network/70-static.network
<span class="o">[</span>Match<span class="o">]</span>
<span class="nv">Name</span><span class="o">=[</span>INTERFACE_NAME<span class="o">]</span>
<span class="o">[</span>Network<span class="o">]</span>
<span class="nv">Address</span><span class="o">=[</span>IP_ADDRESS<span class="o">]</span>/<span class="o">[</span>CIDR_NETMASK<span class="o">]</span>
<span class="nv">Gateway</span><span class="o">=[</span>GATEWAY_IP_ADDRESS<span class="o">]</span>
<span class="nv">DNS</span><span class="o">=[</span>PRIMARY_DNS_IP<span class="o">]</span>
<span class="nv">DNS</span><span class="o">=[</span>SECONDARY_DNS_IP<span class="o">]</span>
</pre></div>
</div>
<p>See the <a class="reference external" href="https://www.freedesktop.org/software/systemd/man/systemd.network.html">systemd-network man page</a>
for more configuration options.</p>
</li>
<li><p>Restart the <cite>systemd-networkd</cite> service:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>systemctl<span class="w"> </span>restart<span class="w"> </span>systemd-networkd
</pre></div>
</div>
</li>
<li><p>Verify your static IP address details have been set:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>networkctl<span class="w"> </span>status
</pre></div>
</div>
</li>
</ol>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../../index.html">
<img class="logo" src="../../_static/clearlinux.png" alt="Logo of Clear Linux* Project Docs"/>
</a></p>
<div>
<h3><a href="../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Assign a static IP address</a><ul>
<li><a class="reference internal" href="#identify-which-program-is-managing-the-interface">Identify which program is managing the interface</a></li>
<li><a class="reference internal" href="#using-networkmanager">Using NetworkManager</a></li>
<li><a class="reference internal" href="#using-systemd-networkd">Using systemd-networkd</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="../maintenance/validate-signatures.html"
title="previous chapter">Validate signatures</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="dpdk.html"
title="next chapter">Use DPDK to send packets between platforms</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../_sources/guides/network/assign-static-ip.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<search id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="dpdk.html" title="Use DPDK to send packets between platforms"
>next</a> |</li>
<li class="right" >
<a href="../maintenance/validate-signatures.html" title="Validate signatures"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../index.html">Documentation for Clear Linux* project</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../index.html" >Guides</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Assign a static IP address</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2022 Intel Corporation. All Rights Reserved..
Last updated on Nov 04, 2024.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
</div>
</body>
</html>