Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
I'm not sure there's a good way to do this. You can't move a process into another network namespace, so you can't accomplish the exact equivalent of your unshare command. Standard iptables or nftables does not have the ability to block traffic by pid. This answer suggests moving the process into a cgroup and then blocking network access for that cgroup.
unsharecommand. Standard iptables or nftables does not have the ability to block traffic by pid. This answer suggests moving the process into a cgroup and then blocking network access for that cgroup.