From f5ed5353ec7a9023d00f58ebaa9da069a9d3c1aa Mon Sep 17 00:00:00 2001 From: Benjamin Collet Date: Mon, 24 Dec 2018 13:31:25 +0100 Subject: [PATCH] Bugfix --- README.md | 24 ++++++++++++++++++------ if-pre-up.d/netns | 3 +++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 82ac2e4..c72576d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ On invocation of `ifup`: * if it does and the interface is configured, the script will invoke `ifup` for this interface inside the namespace. -## `zsh` functions to run commands and start a shell in a namespace +## `zsh` functions to run commands and start a shell in a namespace with a custom prompt ``` nse () { if [ $# -lt 2 ]; then @@ -30,11 +30,8 @@ nse () { fi NS=${1} shift - unshare -m /bin/sh <<-EOF -mount --make-rprivate / -mount --bind /run/network.${NS} /run/network -ip netns exec ${NS} ${@} -EOF + ARGS=${@} + ip netns exec ${NS} unshare -m /bin/sh -c "mount --make-rprivate /;mount --bind /run/network.${NS} /run/network; ${ARGS}" } nss () { @@ -45,4 +42,19 @@ nss () { fi nse $1 zsh -i } + +alias nsr="nsenter -t 1 -n" + +NS=`ip netns identify $$` + +if [ "$NS" ]; then; + NS="/$NS" +fi + +if [ "`id -u`" -eq 0 ]; then + export PS1="%{%}%T%{%} %{%}%n%{%}@%{%}%m${NS} %{%}%~%{%}%#%{%} " +else + export PS1="%{%}%T%{%} %{%}%n%{%}@%{%}%m${NS} %{%}%~%{%}%#%{%} " +fi + ``` diff --git a/if-pre-up.d/netns b/if-pre-up.d/netns index 7a14ca7..fbafd48 100755 --- a/if-pre-up.d/netns +++ b/if-pre-up.d/netns @@ -11,6 +11,9 @@ then if [ ! -f /etc/netns/$IF_NETNS/network/interfaces ]; then touch /etc/netns/$IF_NETNS/network/interfaces fi + if [ ! -f /etc/netns/$IF_NETNS/resolv.conf ]; then + touch /etc/netns/$IF_NETNS/resolv.conf + fi mkdir -p /run/network.${IF_NETNS} rm -rf /run/network.${IF_NETNS}/* ip netns add ${IF_NETNS}