Em versões posteriores do util-linux, unshare
ganhou a opção --map-root-user
. Citando a partir de unshare(1)
versão 2.26.2:
-r, --map-root-user
Run the program only after the current effective user and group IDs have been mapped to the superuser UID and GID in the newly created user namespace. This makes it possible to conveniently gain capabilities needed to manage various aspects of the newly created namespaces (such as configuring interfaces in the network namespace or mounting filesystems in the mount namespace) even when run unprivileged. As a mere convenience feature, it does not support more sophisticated use cases, such as mapping multiple ranges of UIDs and GIDs. This option implies --setgroups=deny.
Então, em sistemas mais novos, você pode executar:
unshare -n -r ping 127.0.0.1
E isso produzirá o esperado Network is unreachable
.