Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Someguy123/8092bdc9834aa210fb4bd1523e9a1c38 to your computer and use it in GitHub Desktop.

Select an option

Save Someguy123/8092bdc9834aa210fb4bd1523e9a1c38 to your computer and use it in GitHub Desktop.
Scripts to support IPv6 networking in Debian pre-boot (initramfs) environment
#!/bin/sh
##########################################################################################
# Script to be placed in /etc/initramfs-tools/hooks/ipv6
#
# These initramfs IPv6 scripts were originally made by zajdee, and were modified by Someguy123
# at Privex Inc. ( https://www.privex.io ) to fix some issues and add debug logging.
#
# It can be found online here: https://gist.github.com/Someguy123/8092bdc9834aa210fb4bd1523e9a1c38
#
# (Original Gist this was based off of (broken script!): https://gist.github.com/zajdee/65aad61f35d3a63c56c7d1cc76c22e14)
#
# Usage:
# Place this and the other script in their respective locations specified at the top,
# make them executable with 'chmod +x /etc/initramfs-tools/{hooks,scripts/init-premount}/ipv6', then
# edit GRUB_CMDLINE_LINUX in /etc/default/grub to add your static IPv6 details.
#
# Syntax: ipv6=addr=<address>/<netmask>,gw=<gateway>,iface=<interface>,forwarding=<0/1>,accept_ra=<0/1/2>
# May optionally add 'll=fe80::1234' to configure a manual link local address
#
# Example: GRUB_CMDLINE_LINUX="ipv6=addr=2a07:e00::333/64,gw=fe80::1,iface=ens18,forwarding=0,accept_ra=0"
#
# After installing the scripts and adjusting your kernel cmdline, run:
#
# sudo update-initramfs -u; sudo upgrade-grub;
#
##########################################################################################
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
if [ ! -f /bin/ip ] && [ ! -f /usr/sbin/ip ] && [ ! -f /sbin/ip ]; then
exit 0
fi
. /usr/share/initramfs-tools/hook-functions
# If you're on Debian, it should be in /bin/ip
# For Ubuntu, this should be in /usr/sbin/ip
# If this fails to detect where 'ip' is, run "which ip" or "whereis ip" to check the correct path of the 'ip' tool
if [ -f /usr/sbin/ip ]; then
copy_exec /usr/sbin/ip
elif [ -f /bin/ip ]; then
copy_exec /bin/ip
elif [ -f /sbin/ip ]; then
copy_exec /sbin/ip
else
echo "WARNING: could not find 'ip' in /bin, /sbin, nor /usr/sbin"
exit 0
fi
#!/bin/sh
##########################################################################################
# Script to be placed in /etc/initramfs-tools/scripts/init-premount/ipv6
#
# These initramfs IPv6 scripts were originally made by zajdee, and were modified by Someguy123
# at Privex Inc. ( https://www.privex.io ) to fix some issues and add debug logging.
#
# It can be found online here: https://gist.github.com/Someguy123/8092bdc9834aa210fb4bd1523e9a1c38
#
# (Original Gist this was based off of (broken script!): https://gist.github.com/zajdee/65aad61f35d3a63c56c7d1cc76c22e14)
#
# Usage:
# Place this and the other script in their respective locations specified at the top,
# make them executable with 'chmod +x /etc/initramfs-tools/{hooks,scripts/init-premount}/ipv6', then
# edit GRUB_CMDLINE_LINUX in /etc/default/grub to add your static IPv6 details.
#
# Syntax: ipv6=addr=<address>/<netmask>,gw=<gateway>,iface=<interface>,forwarding=<0/1>,accept_ra=<0/1/2>
# May optionally add 'll=fe80::1234' to configure a manual link local address
#
# Example: GRUB_CMDLINE_LINUX="ipv6=addr=2a07:e00::333/64,gw=fe80::1,iface=ens18,forwarding=0,accept_ra=0"
#
# After installing the scripts and adjusting your kernel cmdline, run:
#
# sudo update-initramfs -u; sudo upgrade-grub;
#
##########################################################################################
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
parse_options()
{
local v6opts
v6opts="$1"
echo "v6opts='$v6opts'"
addr=""
gw=""
iface=""
accept_ra=0
forwarding=0
local IFS=","
for x in $v6opts; do
case $x in
addr=*)
addr=${x#addr=}
;;
gw=*)
gw=${x#gw=}
;;
iface=*)
iface=${x#iface=}
;;
accept_ra=*)
accept_ra=${x#accept_ra=}
;;
ll=*)
ll=${x#ll=}
;;
forwarding=*)
forwarding=${x#forwarding=}
;;
esac
done
echo -ne "\nV6 Var Dump: \n addr = $addr \n gw = $gw \n iface = $iface \n accept_ra = $accept_ra \n ll = $ll \n forwarding = $forwarding \n"
if [ ! -d /proc/sys/net/ipv6/conf/${iface} ]; then
echo "IPv6: Interface ${iface} not found, sorry."
return 0
fi
echo -ne "IPv6 address: ${addr}\t"
echo "IPv6 gateway: ${gw}"
echo -ne "IPv6 iface: ${iface}\t"
echo "IPv6 link-local address: ${ll}"
echo ${accept_ra} > /proc/sys/net/ipv6/conf/${iface}/accept_ra
echo ${forwarding} > /proc/sys/net/ipv6/conf/${iface}/forwarding
if [ "x${ll}" != "" ]; then
/bin/ip -6 address flush dev ${iface}
/bin/ip -6 address add ${ll} scope link dev ${iface}
fi
/bin/ip link set ${iface} up
/bin/ip -6 address add ${addr} dev ${iface}
if [ "x${gw}" != "" ]; then
/bin/ip -6 route del default
/bin/ip -6 route add default via ${gw} dev ${iface}
fi
# /bin/ip -6 addr show dev ${iface}
return 0
}
case $1 in
# get pre-requisites
prereqs)
prereqs
exit 0
;;
esac
for x in $(cat /proc/cmdline); do
case ${x} in
ipv6=*)
opt="${x#ipv6=}"
modprobe ipv6
# syntax: ipv6=addr=<address>/<netmask>,gw=<gateway>,iface=<interface>,forwarding=<0/1>,accept_ra=<0/1/2>
# colons are not used as delimiters due to them being in use in ipv6 addrs
parse_options ${opt}
;;
esac
done
@lukefor
Copy link
Copy Markdown

lukefor commented Feb 12, 2024

This didn't work for me on debian 12 (ip binary not found on boot despite no errors from the hook script), but I had success with the scripts from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=627164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment