You are using systemd-nspawn to run a container and need to allow it to use the host's network stack directly, without any network namespace isolation. Which option should you pass to systemd-nspawn?
Trap 1: `--private-network`
`--private-network` does the opposite: it creates a new, isolated network namespace for the container with only a loopback interface unless additional interfaces are configured. It is used when you want network isolation, not when you want to share the host's network stack. Using it would prevent the container from reaching the host's network directly.
Trap 2: `--network-namespace=host`
systemd-nspawn does not have a `--network-namespace=host` option. While similar concepts exist in other tools, this exact flag is not valid for systemd-nspawn. The correct way to share the host network namespace is to simply not create a new one, which is the default behavior unless a network-related option is specified.
Trap 3: `--network-interface=host0`
`--network-interface=host0` assigns a specific host interface to the container, but it still places the container in a separate network namespace. The container will have its own network stack and will not share the host's directly. This option is used for macvlan-like setups, not for sharing the host network namespace.
- A
Do not specify any network-related option.
By default, systemd-nspawn does not create a separate network namespace, so the container shares the host's network stack. If you omit all network options such as `--private-network` or `--network-interface`, the container uses the host's interfaces and routing directly. This is the intended way to achieve host network sharing with systemd-nspawn.
- B
`--private-network`
Why it fails: `--private-network` does the opposite: it creates a new, isolated network namespace for the container with only a loopback interface unless additional interfaces are configured. It is used when you want network isolation, not when you want to share the host's network stack. Using it would prevent the container from reaching the host's network directly.
- C
`--network-namespace=host`
Why it fails: systemd-nspawn does not have a `--network-namespace=host` option. While similar concepts exist in other tools, this exact flag is not valid for systemd-nspawn. The correct way to share the host network namespace is to simply not create a new one, which is the default behavior unless a network-related option is specified.
- D
`--network-interface=host0`
Why it fails: `--network-interface=host0` assigns a specific host interface to the container, but it still places the container in a separate network namespace. The container will have its own network stack and will not share the host's directly. This option is used for macvlan-like setups, not for sharing the host network namespace.