Skip to content

Instantly share code, notes, and snippets.

@ahmetozer
Last active Apr 19, 2020
Embed
What would you like to do?
IPv6 docker with not routed network block
#!/bin/bash
if [ ! -z $2 ]
then
netname=$2
fi
if [ ! -z $3 ]
then
netdev=$3
fi
netname=${netname:-bridge}
netdev=${netdev:-main}
function docker-ipv6-neigh-proxy-run() {
docker inspect --format '{{range .Containers}}{{println .IPv6Address}}{{end}}' $netname | cut -d"/" -f 1 | while read ip; do
if [ ! -z $ip ];
then
ip neigh add proxy $ip dev $netdev
echo $ip
# docker-neigh-ipv6-proxy-save
fi
done
}
function docker-ipv6-neigh-proxy-save() {
if [ -z $netname ]
then
echo "You have to provide netname"
else
if [ -z $netdev ]
then
echo "You have to provide netdev"
else
docker inspect --format '{{range .Containers}}{{println .IPv6Address}}{{end}}' $netname | cut -d"/" -f 1 | while read ip; do
if [ ! -z $ip ]
then
grep -Fx "$ip" /etc/dockeripv6/$netname/$netdev >/dev/null || (
echo "netname $netname netdev $netdev ip $ip"
mkdir -p /etc/dockeripv6/$netname
echo $ip >> /etc/dockeripv6/$netname/$netdev
)
fi
done
fi
fi
}
function docker-ipv6-neigh-proxy-apply() {
for netnamedir in /etc/dockeripv6/*/
do
netname=`basename $netnamedir`
for netdevfile in /etc/dockeripv6/$netname/*
do
netdev=`basename $netdevfile`
echo "docker network '$netname' public interface '$netdev'"
while read ip; do
if [ ! -z $ip ];
then
echo "$ip"
ip neigh add proxy $ip dev $netdev
fi
done < /etc/dockeripv6/$netname/$netdev
done
done
#dirs=($(find /etc/dockeripv6/ -type d))
#for netname in "${dirs[@]}"; do
# printf "$netname "
# echo $PWD
#done
}
function docker-ipv6-neigh-proxy-help {
basename=$(basename $0)
echo "
Usage $basename [Options]
OPTIONS= apply, save, run, help
save [NetName] [DevName]
EX. $basename save webnet eth0
run [NetName] [DevName]
EX. $basename run webnet eth0
apply
EX. $basename apply
"
}
# Check If it's sourced
if [[ $_ != $0 ]]
then
case $1 in
run)
docker-ipv6-neigh-proxy-run
;;
apply)
docker-ipv6-neigh-proxy-apply
;;
save)
docker-ipv6-neigh-proxy-save
;;
*)
docker-ipv6-neigh-proxy-help
esac
else
echo 'Docker IPv6 neigh proxy'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment