Separate containers/services from host network

I’m trying to separate my containers/services from my host network, such that they aren’t routed through any potential VPNs running on the host. But I haven’t found a good way to go about this. I’ve tried out microvm.nix but I hit a roadblock with the networking. I found some guides on IP routing but any declarative approach seems to require systemd-networkd which is apparently not very suitable for desktop use (I use my PC as both a desktop and a 24/7 server). What’s the best way to go about this? I would strongly prefer a declarative solution so that I don’t have to run ip commands in the terminal if possible.

Right now I declare my containers through home manager (services.podman.containers.${name}) and it’s worked very well so far, the only problem remaining is the network separation.

Rather than doing the IP routing on the desktop, is it more reasonable to do it on the router? It’s OpenWRT.

Thanks!

1 Like

Tried getting ChatGPT to search around for this and it looks like there are 2 ways to do this.
One way to do this is with some nftables rules and assigning the Podman containers to a systemd slice, then making the rules use an fwmark to route anything from the cgroup of the slice to the correct host interface. The problem is that nftables requires the cgroup to exist when the rules are created, so you need a more complex reconciler design.

The fwmark may also conflict with other software.

There’s also an alternative implementation using a user with JoinsNamespaceOf and PrivateNetwork-based network namespaces instead of an fwmark, although it still requires a reconciler service. If you can get this to work I recommend it.

Sorry for dumping raw ChatGPT output at you, but the summaries above the details blocks are human-written and should at least help you out a bit.

Essentially the reconcilers are one-shot systemd services that are retriggerd on systemd paths and NetworkManager dispatcher scripts, and run shell scripts that use ip and nft commands with pkgs.writeShellApplication and ExecStart/ExecReload/ExecStop.