#!/bin/sh # This file is in the public domain. # # Shell script for the general setup of network namespaces. # This script should be run once at boot time (as root). # Afterwards, the netjail.sh can be used by anyone (with # the right permissions) to create their own network namespace. # set -eu # Be extra safe, even though sudo should already do this. export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # Setup virtual bridge which we will use to connect all # of the builder networks to. BRIDGE=builderbridge brctl addbr $BRIDGE brctl stp $BRIDGE off ip link set dev $BRIDGE up # Connect bridge to host network ip link add tap0 type veth peer name br-tap0 brctl addif $BRIDGE br-tap0 ip link set dev tap0 up ip link set dev br-tap0 up # Configure bridge on host ip addr add 10.42.42.1/24 dev tap0 # Configure IP masquerading/NAT # Obtain list of our network interfaces from /etc/network/interfaces IFCS=`cat /etc/network/interfaces | grep iface | grep -v loopback | awk '{print $2}'` for IFC in $IFCS do iptables --table nat --append POSTROUTING --out-interface $IFC -j MASQUERADE done echo 1 > /proc/sys/net/ipv4/ip_forward