#!/usr/bin/env bash # This script determines the IPv6 address of a given domain. The so found # address is then used to create an IPv4-to-IPv6 tunnel from this device to the # IPv6 address. # [6tunnel](https://packages.debian.org/de/sid/6tunnel) is used to create the # proxy. # # Usage: ./ipv6-mapper.sh set -e DOMAIN=${1} # e.g. mysub.mydomain.com, must have a valid AAAA record HOST_PORT=${2:-443} TARGET_PORT=${3:-443} if ! [ -x "$(command -v 6tunnel)" ]; then >&2 echo "Fatal error: 6tunnel is not installed. Abort." exit 1 fi # Request current ipv6 address IPv6=`dig +short "${DOMAIN}" AAAA` if [ -z "$IPv6" ]; then >&2 echo "Fatal error: IPv6 DNS entry not available. Abort." exit 1 fi echo "---------- [ start ipv4-to-ipv6-bridge ] ----------" echo `date` echo "Found IPv6 address: ${IPv6}" proc_count=`ps -aux | grep "6tunnel ${HOST_PORT} ${IPv6}" | wc -l` if [ proc_count = "0" ]; then # Kill all existing tunnel processes echo "Removing already established tunnel connections on this port" kill -9 `ps -aux | grep "6tunnel ${HOST_PORT}" | awk '{ print $2 }'` # Establish connection to new ip echo "Establish new tunnel connection" 6tunnel ${HOST_PORT} ${IPv6} ${TARGET_PORT} echo "6tunnel connection has been updated. Finish." else echo "6tunnel connection up to date. No need to update connection. Finish." fi echo "---------- [ end ipv4-to-ipv6-bridge ] ----------"