Disabling IPv6 by default when creating a new namespace in Linux

Dheeraj Kandula <[email protected]> Tue, 7 Jun 2022 12:24:39 -0400
Newsgroups gmane.linux.debian.devel.ipv6
Message-ID <CA+qNgxSuibAruJmsSrYQGDH0RjTHZSmffKicfJOeYG0KevAWgA@mail.gmail.com>
--0000000000001ba38b05e0de07aa
Content-Type: text/plain; charset="UTF-8"

Hi All,
          I have been able to disable IPv6 globally by adding the following
sysctls to the /etc/sysctl.conf file.

net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1

When I boot up the machine (it is a VM actually), IPv6 is disabled. But
when I create  a new namespace, IPv6 is enabled by default. I added the
following line to /etc/sysctl.conf file, but still IPv6 is enabled.

net.core.devconf_inherit_init_net=1

I tried with setting the value to 2 and 3 too. The default is 0. But IPv6
was still enabled inside a newly created namespace.

How do I disable IPv6 by default when a new namespace is created?

*My requirement is to have IPv6 disabled globally and in newly created
namespaces*. If the user wants to enable IPv6 in a specific namespace,
he/she can do so with the following command


*sudo nsenter --net=/var/run/netns/<namespace name> sysctl -w
net.ipv6.all.conf.disable_ipv6=0*

Dheeraj

--0000000000001ba38b05e0de07aa
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi All,</div><div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 I have been able to disable IPv6 globally by adding t=
he following sysctls to the /etc/sysctl.conf file.</div><div><br></div><div=
>net.ipv6.conf.all.disable_ipv6=3D1<br>net.ipv6.conf.default.disable_ipv6=
=3D1</div><div><br></div><div>When I boot up the machine (it is a VM actual=
ly), IPv6 is disabled. But when I create=C2=A0 a new namespace, IPv6 is ena=
bled by default. I added the following line to /etc/sysctl.conf file, but s=
till IPv6 is enabled.</div><div><br></div><div>net.core.devconf_inherit_ini=
t_net=3D1</div><div><br></div><div>I tried with setting the value to 2 and =
3 too. The default is 0. But IPv6 was still enabled inside a newly created =
namespace.<br></div><div><br></div><div>How do I disable IPv6 by default wh=
en a new namespace is created? <br></div><div><br></div><div><span style=3D=
"background-color:rgb(238,238,238)"><b>My requirement is to have IPv6 disab=
led globally and in newly created namespaces</b></span>. If the user wants =
to enable IPv6 in a specific namespace, he/she can do so with the following=
 command</div><div><br></div><div><strong>sudo nsenter --net=3D/var/run/net=
ns/&lt;namespace name&gt; sysctl -w net.ipv6.all.conf.disable_ipv6=3D0<br><=
/strong></div><div><br></div><div>Dheeraj</div><div><br></div></div>

--0000000000001ba38b05e0de07aa--