Run a systemd unit in a specified network namespace

9,151

Solution 1

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.

Solution 2

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.

Share:
9,151

Related videos on Youtube

A__A__0
Author by

A__A__0

Updated on September 18, 2022

Comments

  • A__A__0
    A__A__0 almost 2 years

    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.

    • Michael Hampton
      Michael Hampton over 8 years
      You can do this very easily with JoinsNamespaceOf= if systemd created the namespace for the other process.
    • A__A__0
      A__A__0 over 8 years
      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?
    • Michael Hampton
      Michael Hampton over 8 years
      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.
    • A__A__0
      A__A__0 over 8 years
      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.