Staging
v0.8.1
https://github.com/torvalds/linux
Raw File
Tip revision: b13baccc3850ca8b8cccbf8ed9912dbaa0fdf7f3 authored by Linus Torvalds on 12 June 2022, 23:11:37 UTC
Linux 5.19-rc2
Tip revision: b13bacc
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