-
-
Save s4l3h1/b76e8cd679aa0cdd5fb1dde6ee5541c2 to your computer and use it in GitHub Desktop.
Revisions
-
thiagokronig created this gist
Aug 5, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ # Fortemente baseado em https://github.com/jpetazzo/pipework function add_veth_pair { pid=$1 ; ipaddr=$2 ; container_ifname=$3 echo "Add interface $container_ifname with ip $ipaddr to container pid $pid" local_ifname="v${container_ifname}l${pid}" guest_ifname="v${container_ifname}g${pid}" bridge='docker0' mtu=$(ip link show $bridge | awk '{print $5}') if ip link show "$local_ifname" >/dev/null 2>&1 ; then ip link del "$local_ifname" fi ip link add name "$local_ifname" mtu "$mtu" type veth peer name "$guest_ifname" mtu "$mtu" ip link set "$local_ifname" master "$bridge" ip link set "$local_ifname" up ip link set "$guest_ifname" netns "$pid" ip netns exec "$pid" ip link set "$guest_ifname" name "$container_ifname" ip netns exec "$pid" ip addr add "$ipaddr" dev "$container_ifname" ip netns exec "$pid" ip link set "$container_ifname" up ipaddr=$(echo "$ipaddr" | cut -d/ -f1) ip netns exec "$pid" arping -c 1 -A -I "$container_ifname" "$ipaddr" >/dev/null 2>&1 | : }