Jamesits / systemd-named-netns

Use named netns (net namespace) with systemd services!
GNU General Public License v3.0
132 stars 33 forks source link

netns raw on specific interface, via configuration #30

Open almightiest opened 2 years ago

almightiest commented 2 years ago

Is there a way (that I'm currently not able to figure out) to configure netns to simply bring in an external "eno2" ethernet device and run dhcp4 on it? Bonus to disable ipv6. All of my vlan and routing is done in hardware (switch layer 2+, router). I'm just trying to isolate certain systemctl services to a single network, which gets pretty complicated outside of netns.

Here's the script I have to run after running systemctl start netns@my_ns.service:

ip link set dev eno2 netns my_ns
chnetns my_ns sysctl net.ipv6.conf.eno2.disable_ipv6=1
ip -n my_ns link set eno2 up
ip -n my_ns link set lo up
ip netns exec my_ns dhclient eno2

Ideally this would be done as part of the service itself. I took a look inside netnsninit script but didn't see any kind of option for this. Maybe I'm just overlooking it!

Jamesits commented 2 years ago

Hi,

You can add your script before this line:

https://github.com/Jamesits/systemd-named-netns/blob/d7fb889196ca921399e461d35de42cae59802a3e/scripts/netnsinit#L178

It is so hard to take an abstraction of how everyone use netns, so please just treat my scripts as a template and roll your own ones that fit your requirements.

almightiest commented 2 years ago

Thank you - i'll see if i can make that change and enable it via config and submit a PR - once i find some time :-D