You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[RFE] systemd-networkd set netns for netdev #11103
Is your feature request related to a problem? Please describe.
I would like to be able to create network device inside a specified network namespace.
Describe the solution you'd like
Inside [NetDev] section of a netdev unit type I would like to have an additional option - NetnsName which should allow specifying the name for network namespace in which networkd will create net device. If specified namespace doesn't exist then networkd should create it before creating the device.
Describe alternatives you've considered
Shell script? :/
Reacted by Oliver Ford, ikorolev93, Vladimir Matveev, Cooper Lees, William Johansson, Aluísio Augusto Silva Gonçalves, Chris Bouchard, DasSkelett, FallenWarrior2k, Klaus Frank and 71 more
To complete that functionality NetnsName should probably appear also in [Match] section of a network unit to allow configuration of a device created inside the namespace.
Please consider that it may be important to support "NetnsNameAtBirth" besides "NetnsName".
So if only NetnsName is set systemd will create the device in the NetnsName and keep it there.
If NetnsNameAtBirth is set alongside NetnsName, the device will be created in the NetnsNameAtBirth namespace and then be moved to NetnsName.
A special value for NetnsNameAtBirth of "create-than-move" (?), would make systemd create the device first (without setting a namespace) AND THEN move the device to NetnsName
Routing & Network Namespace Integration
Like all Linux network interfaces, WireGuard integrates into the network namespace infrastructure. This means an administrator can have several entirely different networking subsystems and choose which interfaces live in each.
WireGuard does something quite interesting. When a WireGuard interface is created (with ip link add wg0 type wireguard), it remembers the namespace in which it was created. "I was created in namespace A." Later, WireGuard can be moved to new namespaces ("I'm moving to namespace B."), but it will still remember that it originated in namespace A.
WireGuard uses a UDP socket for actually sending and receiving encrypted packets. This socket always lives in namespace A – the original birthplace namespace. This allows for some very cool properties. Namely, you can create the WireGuard interface in one namespace (A), move it to another (B), and have cleartext packets sent from namespace B get sent encrypted through a UDP socket in namespace A.
(Note that this same technique is available to userspace TUN-based interfaces, by creating a socket file-descriptor in one namespace, before changing to another namespace and keeping the file-descriptor from the previous namespace open.)
This opens up some very nice possibilities.
Ordinary Containerization
The most obvious usage of this is to give containers (like Docker containers, for example) a WireGuard interface as its sole interface.
(...)
Routing All Your Traffic
A less obvious usage, but extremely powerful nonetheless, is to use this characteristic of WireGuard for redirecting all of your ordinary Internet traffic over WireGuard. But first, let's review the old usual solutions for doing this:
(...)
Reacted by Oliver Ford, asymmetric, LaserEyess, Vladimir Matveev, Andrew Hodges, Elias Probst, Soha Jin, Chris Bouchard, FallenWarrior2k, Gert van Dijk and 21 more
This is already touched in the PR, but how far should the scope of namespace-support go?
I would like to have a namespaced tun network, with atleast 2 services accessing it.
namespaced tun .netdev
namespaced tun .network
a namespaced Listen .socket
a .service being both able to get fds/stdin from multiple different netns,
aswell as inheriting the activating socket ns.
tftp-hpa for example would get the UDP connect request forwarded via stdin, then has to open an UDP socket for communication in the correct netns.
a .service that serves the namespaced tun enpdoint
one or more .services that are namespace-aware but should be started after the namespace and -network is operational.
So there would be a significant amount of work to get this done via systemd, but this would allow to setup networks and services in the same fashion instead of alot of sysv-style patchwork.
On the other hand, this goes a couple steps into container territory, but with the ability to have services accessing multiple containers at once.
@yuwata As far as I can tell - apologies if I've missed it - #14915 does not support the differing birth and running namespace use case that @mbello mentioned above in #11103 (comment)?
Activity
[-][RFE]systemd-networkd set netns for netdev[/-][+][RFE] systemd-networkd set netns for netdev[/+]mskarbek commentedon Dec 10, 2018
To complete that functionality
NetnsNameshould probably appear also in[Match]section of a network unit to allow configuration of a device created inside the namespace.mbello commentedon Dec 14, 2018
Please consider that it may be important to support "NetnsNameAtBirth" besides "NetnsName".
So if only NetnsName is set systemd will create the device in the NetnsName and keep it there.
If NetnsNameAtBirth is set alongside NetnsName, the device will be created in the NetnsNameAtBirth namespace and then be moved to NetnsName.
A special value for NetnsNameAtBirth of "create-than-move" (?), would make systemd create the device first (without setting a namespace) AND THEN move the device to NetnsName
Below I will copy part of the explanation of why this is an important feature and you can read more (along with actual use cases for both TUN and WG interfaces here https://www.wireguard.com/netns/
nolange commentedon Feb 13, 2020
This is already touched in the PR, but how far should the scope of namespace-support go?
I would like to have a namespaced tun network, with atleast 2 services accessing it.
aswell as inheriting the activating socket ns.
tftp-hpa for example would get the UDP connect request forwarded via stdin, then has to open an UDP socket for communication in the correct netns.
So there would be a significant amount of work to get this done via systemd, but this would allow to setup networks and services in the same fashion instead of alot of sysv-style patchwork.
On the other hand, this goes a couple steps into container territory, but with the ability to have services accessing multiple containers at once.
ngortheone commentedon Mar 10, 2020
@nolange I would like to add to the list of usecases:
Peernamespacedyuwata commentedon Mar 11, 2020
#14915 will support such a use case.
OJFord commentedon Apr 20, 2020
@yuwata As far as I can tell - apologies if I've missed it - #14915 does not support the differing birth and running namespace use case that @mbello mentioned above in #11103 (comment)?
daiaji commentedon Feb 2, 2024
For container users, this is really good, but it hasn't been completed.
hurutparittya commentedon Mar 10, 2025
Is there any ongoing effort to enable this or similar functionality?
aojea commentedon Jun 21, 2025
For containers , with the new feature added to the OCI spec https://github.com/opencontainers/runtime-spec/blob/main/config-linux.md#network-devices , it is now possible to delegate to the runtime moving the interface to the network namespace
So systemd can create the interface and users can indicate the runtime to move it