netns 587 B

1234567891011121314151617181920
  1. #!/bin/bash
  2. set -e
  3. if [ -n "${IF_NETNS}" ]
  4. then
  5. # Create netns if it doesn't already exist, and bring up the loopback
  6. if ! (ip netns list | grep -qx ${IF_NETNS})
  7. then
  8. mkdir -p /etc/netns/$IF_NETNS/network/{if-down.d,if-post-down.d,if-pre-up.d,if-up.d}
  9. if [ ! -f /etc/netns/$IF_NETNS/network/interfaces ]; then
  10. touch /etc/netns/$IF_NETNS/network/interfaces
  11. fi
  12. mkdir -p /run/network.${IF_NETNS}
  13. rm -rf /run/network.${IF_NETNS}/*
  14. ip netns add ${IF_NETNS}
  15. ip netns exec ${IF_NETNS} ip link set lo up
  16. fi
  17. ip link set ${IFACE} netns ${IF_NETNS}
  18. fi