Skip to content

Instantly share code, notes, and snippets.

@HoffmannP
Last active March 31, 2019 01:57
Show Gist options
  • Save HoffmannP/e60925a6d9718b9806bee97ce738c0d9 to your computer and use it in GitHub Desktop.
Save HoffmannP/e60925a6d9718b9806bee97ce738c0d9 to your computer and use it in GitHub Desktop.
#!/bin/bash
clear
echo "configure for my network settings"
netDev="wlp3s0"
netPrefix="192.168.0"
macNet="fritz"
shimDev="${macNet}0"
ipHost="35"
ipShim="130"
ipGateway="1"
theInternet="8.8.8.8"
timeToSettle=3
echo "some sources say promisc mode on '$netDev' is neccessary"
sudo ip link set $netDev promisc on
echo "create"
echo -n " * macvlan network '$macNet': "
docker network create -d macvlan -o parent=$netDev \
--subnet=${netPrefix}.0/24 \
--gateway=${netPrefix}.$ipGateway \
--aux-address="$shimDev=${netPrefix}.${ipShim}" \
--ip-range=${netPrefix}.128/26 \
$macNet
echo -n " * checker container: "
docker run -dit --name container --net $macNet alpine ash
echo -n " * sibling container: "
docker run -dit --name nginx --net $macNet nginx
echo -n " * shimInterface '$shimDev' "
sudo ip link add $shimDev link $netDev type macvlan mode bridge && \
sudo ip addr add ${netPrefix}.130/26 dev $shimDev && \
sudo ip link set $shimDev up && \
# # sudo ip addr add ${netPrefix}.150/32 dev $shimDev && \
# sudo ip link set $shimDev up && \
# sudo ip route add ${netPrefix}.128/26 dev $shimDev && \
echo "up"
while [[ $timeToSettle -ge 0 ]]
do
printf "\rgive everything some time to settle (%2dsec)" $timeToSettle
sleep 1s
let timeToSettle=$timeToSettle-1
done
echo ""
echo -n "cmp external and internal IP of the checker container: "
containerIP=$(docker inspect -f "{{ .NetworkSettings.Networks.${macNet}.IPAddress }}" container)
echo -n "$containerIP <=> "
docker exec container ip addr show eth0 | grep inet | cut -d' ' -f6
docker exec container route
route
echo "ping from the checker container"
for target in nginx ${netPrefix}.${ipHost} ${netPrefix}.${ipShim} ${netPrefix}.${ipGateway} $theInternet
do
echo -n " * $target> "
docker exec container ping -c3 -q -w2 $target | egrep -o '[0-9]*% packet loss'
done
# echo "from host via '$netDev':"
# for target in ${netPrefix}.${ipGateway} $theInternet $containerIP
# do
# echo -n " * $target> "
# ping -c3 -q -w2 -I $netDev $target | egrep -o '[0-9]*% packet loss'
# done
#
# echo "from host via '$shimDev':"
# for target in ${netPrefix}.${ipGateway} $theInternet $containerIP
# do
# echo -n " * $target> "
# ping -c3 -q -w2 -I $shimDev $target | egrep -o '[0-9]*% packet loss'
# done
echo "from host [any]"
for target in ${netPrefix}.${ipGateway} $theInternet $containerIP
do
echo -n " * $target> "
ping -c3 -q -w2 $target | egrep -o '[0-9]*% packet loss'
done
echo "cleanup"
echo -n " * delete checker "; docker rm -f container
echo -n " * delete container "; docker rm -f nginx
echo -n " * delete network "; docker network rm $macNet
echo -n " * delete shimInterface '$shimDev'"; sudo ip link delete $shimDev; echo
echo -n " * turn off promisc on '$netDev'"; sudo ip link set $netDev promisc off; echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment