Moving unconnected NICs into a container namespace
As discussed previously, sometimes you might want to move NICs into a container network namespace. The following script will ease this process.
#!/bin/bash
# Usage: move-nics.sh network-router-container
docker-pid() { docker inspect --format="" $1 ; }
DSTCT=${1}
DSTPID=$(docker-pid $DSTCT)
devices() { nmcli -t -f device,type,connection device) ; }
UNCONNECTEDETH=$(devices | egrep "ethernet:--$" | cut -d ":" -f1)
for NIC in $UNCONNECTEDETH
do
echo "Moving '$NIC' to netns of '$DSTPID'"
ip link set netns ${DSTPID} $NIC
done
A longer version is available here.
::: {#footer} [ May 11th, 2015 12:13pm ]{#timestamp} [fedora]{.tag} [docker]{.tag} [container]{.tag} [nmcli]{.tag} [NetworkManager]{.tag} :::