ifupdown-netns/if-pre-up.d/netns

24 lines
694 B
Text
Raw Normal View History

2018-04-07 19:40:38 +00:00
#!/bin/bash
set -e
if [ -n "${IF_NETNS}" ]
then
# Create netns if it doesn't already exist, and bring up the loopback
if ! (ip netns list | grep -qx ${IF_NETNS})
then
mkdir -p /etc/netns/$IF_NETNS/network/{if-down.d,if-post-down.d,if-pre-up.d,if-up.d}
if [ ! -f /etc/netns/$IF_NETNS/network/interfaces ]; then
touch /etc/netns/$IF_NETNS/network/interfaces
fi
2018-12-24 12:31:25 +00:00
if [ ! -f /etc/netns/$IF_NETNS/resolv.conf ]; then
touch /etc/netns/$IF_NETNS/resolv.conf
fi
2018-04-07 19:40:38 +00:00
mkdir -p /run/network.${IF_NETNS}
rm -rf /run/network.${IF_NETNS}/*
ip netns add ${IF_NETNS}
ip netns exec ${IF_NETNS} ip link set lo up
fi
ip link set ${IFACE} netns ${IF_NETNS}
fi