X-Git-Url: https://iankelling.org/git/?p=newns;a=blobdiff_plain;f=newns;h=823d184b5b07b323d17acbe91a46b5b2a3ccd694;hp=2896cf21d942162ccfe4d2472af2e962450ad937;hb=6c826f3613b0c3b86257b111b3078013fdf34b78;hpb=b4463d1e1bfd7d54451005aff0f6ae1f649042d1 diff --git a/newns b/newns index 2896cf2..823d184 100755 --- a/newns +++ b/newns @@ -157,7 +157,7 @@ dexec() { ip netns exec default "$@"; } # background: head -n1 is defensive. Not sure if there is some weird feature # for 2 routes to be 0/0. -gateway_if=$(ipd route list exact 0/0 | head -n1| sed -r 's/.*\s(\S+)\s*$/\1/') +gateway_if=$(ipd route list exact 0/0 | head -n1| sed -r 's/.*dev\s+(\S+).*/\1/') nat() { dexec iptables -t nat $1 POSTROUTING -o $gateway_if -j MASQUERADE \ -m comment --comment "systemd network namespace nat"; } @@ -190,13 +190,26 @@ start() { mkdir -p /root/mount_namespaces if ! mountpoint /root/mount_namespaces >/dev/null; then mount --bind /root/mount_namespaces /root/mount_namespaces - mount --make-private /root/mount_namespaces fi + # note: This is outside the mount condition because I've mysteriously + # had this become shared instead of private, perhaps it + # got remounted somehow and lost the setting. + mount --make-private /root/mount_namespaces if [[ ! -e /root/mount_namespaces/$nn ]]; then touch /root/mount_namespaces/$nn fi if ! mountpoint /root/mount_namespaces/$nn >/dev/null; then - unshare --mount=/root/mount_namespaces/$nn + # documentation on propagation is a bit weird because it + # confusingly talks about binds, namespaces, and mirrors (which + # seems to be just another name for bind), shared subtrees + # (which seems to a term for binds and namespaces), and does not + # properly specify whether the documentation applies to binds, + # namespaces, or both. Notably, propagation for binds is marked + # on the original mount point, and propagation for a mount + # namespace is marked on mounts within the namespace. Here, we + # specify that we want mount changes propagated to us, but not + # back. + unshare --propagation slave --mount=/root/mount_namespaces/$nn fi #### end mount namespace setup ####