Application container attached to WireGuard interface?

Hi,

I am trying to have an instance (application container) attached to a WireGuard interface on the host, essentially to force all traffic from that instance to go through the tunnel.

I am not an expert when it comes to network namespaces, veth/bridge interfaces etc. so I would appreciate any advice for how to make this happen.

My first thought was that having the WireGuard interface on host as normal with the AllowedIPs `0.0.0.0/0, ::/0` would cause all other host traffic to go through the tunnel too since it creates routes, which I don’t want. So I thought to put this WireGuard interface into a separate namespace, but then I couldn’t figure out how to attach it to an instance from that other namespace.

Any advice is appreciated!

The cleanest way is to run the WireGuard client inside the container instead of on the host: the tunnel then lives in the container’s own network namespace, so AllowedIPs 0.0.0.0/0 affects only that instance and the host keeps its normal routing. The host only needs the wireguard kernel module - stgraber has pointed out on this forum that Incus can load it for the instance with linux.kernel_modules=wireguard; inside the container you install wireguard-tools and configure wg0 as usual. One known pitfall with unprivileged containers: if wg-quick fails, the cause in another thread here was the missing iptable_raw module on the host, which wg-quick’s fwmark rules need. This way you skip the separate-namespace and veth plumbing entirely.

Thank you Rei, I will consider that option again, but to be honest I was hoping to avoid it and leave the application container (not system container) untouched internally.

How would it look with the extra plumbing? I searched online but couldn’t find something like this for incus, though perhaps I didn’t search the right terms.