Bugfix
This commit is contained in:
parent
a59b876c84
commit
f5ed5353ec
2 changed files with 21 additions and 6 deletions
24
README.md
24
README.md
|
@ -20,7 +20,7 @@ On invocation of `ifup`:
|
||||||
* if it does and the interface is configured, the script will invoke `ifup`
|
* if it does and the interface is configured, the script will invoke `ifup`
|
||||||
for this interface inside the namespace.
|
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 () {
|
nse () {
|
||||||
if [ $# -lt 2 ]; then
|
if [ $# -lt 2 ]; then
|
||||||
|
@ -30,11 +30,8 @@ nse () {
|
||||||
fi
|
fi
|
||||||
NS=${1}
|
NS=${1}
|
||||||
shift
|
shift
|
||||||
unshare -m /bin/sh <<-EOF
|
ARGS=${@}
|
||||||
mount --make-rprivate /
|
ip netns exec ${NS} unshare -m /bin/sh -c "mount --make-rprivate /;mount --bind /run/network.${NS} /run/network; ${ARGS}"
|
||||||
mount --bind /run/network.${NS} /run/network
|
|
||||||
ip netns exec ${NS} ${@}
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nss () {
|
nss () {
|
||||||
|
@ -45,4 +42,19 @@ nss () {
|
||||||
fi
|
fi
|
||||||
nse $1 zsh -i
|
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="%{[33;36;1m%}%T%{[0m%} %{[33;34;1m%}%n%{[0m[33;33;1m%}@%{[33;37;1m%}%m${NS} %{[33;32;1m%}%~%{[0m[33;33;1m%}%#%{[0m%} "
|
||||||
|
else
|
||||||
|
export PS1="%{[33;36;1m%}%T%{[0m%} %{[33;31;1m%}%n%{[0m[33;33;1m%}@%{[33;37;1m%}%m${NS} %{[33;32;1m%}%~%{[0m[33;33;1m%}%#%{[0m%} "
|
||||||
|
fi
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -11,6 +11,9 @@ then
|
||||||
if [ ! -f /etc/netns/$IF_NETNS/network/interfaces ]; then
|
if [ ! -f /etc/netns/$IF_NETNS/network/interfaces ]; then
|
||||||
touch /etc/netns/$IF_NETNS/network/interfaces
|
touch /etc/netns/$IF_NETNS/network/interfaces
|
||||||
fi
|
fi
|
||||||
|
if [ ! -f /etc/netns/$IF_NETNS/resolv.conf ]; then
|
||||||
|
touch /etc/netns/$IF_NETNS/resolv.conf
|
||||||
|
fi
|
||||||
mkdir -p /run/network.${IF_NETNS}
|
mkdir -p /run/network.${IF_NETNS}
|
||||||
rm -rf /run/network.${IF_NETNS}/*
|
rm -rf /run/network.${IF_NETNS}/*
|
||||||
ip netns add ${IF_NETNS}
|
ip netns add ${IF_NETNS}
|
||||||
|
|
Loading…
Reference in a new issue