Skip to content

Instantly share code, notes, and snippets.

@w1ndy
Created September 12, 2022 09:53
Show Gist options
  • Save w1ndy/f037efb028e8b7b3a934d334a3da9455 to your computer and use it in GitHub Desktop.
Save w1ndy/f037efb028e8b7b3a934d334a3da9455 to your computer and use it in GitHub Desktop.
Delegate IPv6 PD from Remote Router
# This is the network config written by 'subiquity'
network:
ethernets:
enp2s0:
accept-ra: no
addresses:
- 192.168.1.2/24
- $IPV6_ADDR
gateway4: 192.168.1.1
gateway6: fe80::8ede:f9ff:feb7:2dbc
nameservers:
addresses:
- 192.168.1.1
search: []
version: 2
interface enp2s0 {
AdvSendAdvert on;
prefix $IPV6_PD {
AdvAutonomous on;
};
RDNSS fe80::2e0:70ff:fe86:cebb {};
};
#!/bin/bash
CURRENT_IPV6_PD=$(ip -6 addr | grep -Po '[\da-z:]+::c9b/64' | sed 's/::c9b\/64/::\/60/g')
ROUTER_IPV6_PD=$(ssh [email protected] "ip -6 addr | grep -Po '[\da-z:]+/60' | sed 's/::1/::/g'")
echo "Current: $CURRENT_IPV6_PD, Router: $ROUTER_IPV6_PD"
if [ ! -z "$ROUTER_IPV6_PD" ] && [ "$ROUTER_IPV6_PD" != "$CURRENT_IPV6_PD" ]; then
echo "New IPv6 prefix detected: $ROUTER_IPV6_PD"
export IPV6_ADDR=$(echo $ROUTER_IPV6_PD | sed "s/::\/60/::c9b\/64/g")
envsubst < /etc/netplan/00-installer-config.yaml.template > /etc/netplan/00-installer-config.yaml
netplan apply
export IPV6_PD="$ROUTER_IPV6_PD"
envsubst < /etc/radvd.conf.template > /etc/radvd.conf
systemctl restart radvd
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment