8

I would like to instruct systemd to 'run a unit' in a specified, pre-existing network namespace, in particular to start the unit's process(es) in the namespace.

A__A__0
  • 423
  • 2
  • 8
  • 17
  • You can do this very easily with `JoinsNamespaceOf=` if systemd created the namespace for the other process. – Michael Hampton Dec 18 '15 at 00:07
  • 1
    Yeah I spotted that, but systemd did not create the namespace. (There is no other process involved). Is the approach to create a unit to encapsulate the creation of the namespace, and then refer to that unit name in JoinsNamespaceOf? – A__A__0 Dec 18 '15 at 00:14
  • You're probably at the level of complexity where you should just start using containers via some existing technology, rather than trying to roll them yourself. – Michael Hampton Dec 18 '15 at 00:16
  • 2
    I see. Unfortunately I'm simply trying to do this to debug a problem. I will start the process outside of systemd for the purpose of debugging. – A__A__0 Dec 18 '15 at 00:19

2 Answers2

10

Looks like it's now possible to do this in systemd 242 via the NetworkNamespacePath option: announcement.

Check out the docs for use it here.

Dan
  • 301
  • 3
  • 6
3

systemd is not fully compatible with network namespace as the issues https://github.com/systemd/systemd/issues/2741, may add some other key words like ExecStart to add network namespace switch into namespace before running service.

changliwei
  • 49
  • 3
  • The `NetworkNamespacePath` option was introduced in 2019. Consequently, I believe this answer is out of date and/or misleading, and the answer should be updated or deleted. – mpb Jul 09 '23 at 21:39