Staging
v0.8.1
https://github.com/torvalds/linux
Raw File
Tip revision: 26291c54e111ff6ba87a164d85d4a4e134b7315c authored by Linus Torvalds on 30 January 2022, 13:37:07 UTC
Linux 5.17-rc2
Tip revision: 26291c5
in_netns.sh
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# Execute a subprocess in a network namespace

set -e

readonly NETNS="ns-$(mktemp -u XXXXXX)"

setup() {
	ip netns add "${NETNS}"
	ip -netns "${NETNS}" link set lo up
}

cleanup() {
	ip netns del "${NETNS}"
}

trap cleanup EXIT
setup

ip netns exec "${NETNS}" "$@"
exit "$?"
back to top