I'm trying to launch an app inside a network namespace from a systemd service. I tried using NetworkNamespacePath=
but when I use it all network requests fail. If I launch the app in ExecStart
using ip netns exec
it works, but it's not very clean and I have to reset the user using sudo
. What am I doing wrong with NetworkNamespacePath=
?
I don't think it should matter much but I'm running Ubuntu Server 20.04 LTS. This is my service file.
[Unit]
Description=My Service
# netns.service sets up the network namespace
After=network-online.target netns.service
Requires=network-online.target netns.service
[Service]
Type=simple
# The following doesn't work, app starts but every network request fails
NetworkNamespacePath=/run/netns/mynetns
User=user
Group=user
ExecStart=/usr/bin/app
# If I change it to this, it works
ExecStart=/usr/sbin/ip netns exec mynetns sudo -u user /usr/bin/app
[Install]
WantedBy=multi-user.target