<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Amelentyev</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Amelentyev"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Amelentyev"/>
	<updated>2026-05-02T00:52:35Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Netns&amp;diff=26937</id>
		<title>Netns</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Netns&amp;diff=26937"/>
		<updated>2024-07-21T19:32:02Z</updated>

		<summary type="html">&lt;p&gt;Amelentyev: Fix a syntax error in the config example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:netns}}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;netns&#039;&#039;&#039; (network namespaces) are another instance of the network stack with its own network devices (links), ip setup and firewall rules. Besides of using netns for building containers they can be used to get a stricter isolation than using [[VRF]]s.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
&lt;br /&gt;
The packages and patches described in this article are available in Alpine edge and ≥3.19.&lt;br /&gt;
&lt;br /&gt;
== netns management ==&lt;br /&gt;
&lt;br /&gt;
=== iproute2 ===&lt;br /&gt;
&lt;br /&gt;
Netns can be ad-hoc managed using the &amp;lt;code&amp;gt;ip netns&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
{{cmd|&amp;lt;nowiki&amp;gt;# ip netns&lt;br /&gt;
# ip netns add tenant1&lt;br /&gt;
# ip netns del tenant1&lt;br /&gt;
# ip netns exec tenant1 ip -br link&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== ifstate ===&lt;br /&gt;
&lt;br /&gt;
[https://ifstate.net IfState], a declarative network configuration tool, is full netns aware since IfState 1.9.0. The following config example creates a wireguard tunnel and a vlan sub-interface. The wireguard link &amp;lt;code&amp;gt;wg0&amp;lt;/code&amp;gt; and the vlan sub-interface are moved into the &amp;lt;code&amp;gt;vpn&amp;lt;/code&amp;gt; netns.&lt;br /&gt;
&lt;br /&gt;
{{cat|/etc/ifstate/config.yml|&amp;lt;nowiki&amp;gt;# root netns&lt;br /&gt;
interfaces:&lt;br /&gt;
  - name: eth0&lt;br /&gt;
    addresses:&lt;br /&gt;
    - 198.51.100.2/31&lt;br /&gt;
    link:&lt;br /&gt;
      state: up&lt;br /&gt;
      kind: physical&lt;br /&gt;
routing:&lt;br /&gt;
  routes:&lt;br /&gt;
    - to: 0.0.0.0/0&lt;br /&gt;
      via: 198.51.100.1&lt;br /&gt;
  rules: []&lt;br /&gt;
&lt;br /&gt;
namespaces:&lt;br /&gt;
  # &amp;quot;vpn&amp;quot; netns&lt;br /&gt;
  vpn:&lt;br /&gt;
    interfaces:&lt;br /&gt;
    - name: eth0.42&lt;br /&gt;
      addresses:&lt;br /&gt;
      - 192.0.2.1/25&lt;br /&gt;
      link:&lt;br /&gt;
        state: up&lt;br /&gt;
        kind: vlan&lt;br /&gt;
        vlan_id: 42&lt;br /&gt;
        link: eth0&lt;br /&gt;
        # link to eth0 in root netns&lt;br /&gt;
        link_netns: null&lt;br /&gt;
    - name: wg0&lt;br /&gt;
      addresses:&lt;br /&gt;
      - 192.0.2.254/30&lt;br /&gt;
      link:&lt;br /&gt;
        state: up&lt;br /&gt;
        kind: wireguard&lt;br /&gt;
        # bind wireguard to the root netns&lt;br /&gt;
        bind_netns: null&lt;br /&gt;
      wireguard:&lt;br /&gt;
        private_key: !include /etc/wireguard/secret.key&lt;br /&gt;
        peers:&lt;br /&gt;
        - public_key: 3Eimby+9YtJwtx+peCsz6RiubRqAp+cATHNiGWsUsEU=&lt;br /&gt;
          endpoint: 203.0.113.42&lt;br /&gt;
          persistent_keepalive_interval: 30&lt;br /&gt;
          allowedips:&lt;br /&gt;
          - 0.0.0.0/0&lt;br /&gt;
    routing:&lt;br /&gt;
      routes:&lt;br /&gt;
        - to: 0.0.0.0/0&lt;br /&gt;
          dev: wg0&lt;br /&gt;
      rules: []&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
== netns-based Service Isolation ==&lt;br /&gt;
&lt;br /&gt;
Services can be run isolated in a netns (&#039;&#039;&#039;and&#039;&#039;&#039; [[VRF]] inside the netns) when running at least OpenRC 0.49.0-r1. You can set the &amp;lt;code&amp;gt;$netns&amp;lt;/code&amp;gt; variable for the service in {{path|/etc/conf.d}} in most cases.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The netns must already be created before a service can be started inside of it!&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== netns-compatible initd scripts ==&lt;br /&gt;
&lt;br /&gt;
Not all initd scripts might be netns compatible. Some network stack related packages have been patched to be netns aware:&lt;br /&gt;
&lt;br /&gt;
* ipset&lt;br /&gt;
* iptables&lt;br /&gt;
* nftables&lt;br /&gt;
&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Amelentyev</name></author>
	</entry>
</feed>