Skip to content

Instantly share code, notes, and snippets.

@bryceml
Created May 11, 2017 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryceml/cf0e76f48a4a7d53e7e97b81bc49d471 to your computer and use it in GitHub Desktop.
Save bryceml/cf0e76f48a4a7d53e7e97b81bc49d471 to your computer and use it in GitHub Desktop.
dhclient exit script for dhcpv6 prefix delegation, used on google fiber with debian 9
#!/bin/bash
# vim:tw=80:tabstop=2:shiftwidth=2
# Copyright (c) 2012-present, Phil Dibowitz <phil@ipom.com>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in
# binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
# * Neither the name of the author nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# You can find the latest version of this at:
# https://github.com/jaymzh/v6-gw-scripts
# This is a dhclient exit script for dhcpv6 prefix delegation, used on google fiber with debian 9
# This script is a fork of the original at https://github.com/jaymzh/v6-gw-scripts
# Place it in /etc/dhcp/dhclient-exit-hooks.d
INT_IFACE='enp3s0' # Edit this
EXT_IFACE='enp1s0.2' # Edit this
ipv6_prefix_setup() {
current_ip=$(/sbin/ip -6 addr show dev ${INT_IFACE} scope global |\
/usr/bin/awk '/inet6/ {print $2}')
current_prefix=$(echo ${current_ip} | /bin/sed -e 's@::1/64@::/56@')
if [ "${current_prefix}" = "${new_ip6_prefix}" ] ; then
return
fi
# Setup the new IP
new_ip=$(echo ${new_ip6_prefix} | /bin/sed -e 's@::/56@::1/64@g')
if [ ! -z "${current_ip}" ] ; then
/bin/ip -6 addr del ${current_ip} dev ${INT_IFACE}
fi
/bin/ip link set dev ${INT_IFACE} up
/bin/ip -6 addr add ${new_ip} dev ${INT_IFACE}
}
if [ "${interface}" != "${EXT_IFACE}" ] ; then
return
fi
case "${reason}" in
BOUND6|REBIND6)
# We will get called twice here - once for the temp address
# and once for the prefix. We only care about the prefix.
if [ ! -z "${new_ip6_prefix}" ] ; then
ipv6_prefix_setup
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment