Created
September 12, 2022 09:53
-
-
Save w1ndy/f037efb028e8b7b3a934d334a3da9455 to your computer and use it in GitHub Desktop.
Delegate IPv6 PD from Remote Router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface enp2s0 { | |
AdvSendAdvert on; | |
prefix $IPV6_PD { | |
AdvAutonomous on; | |
}; | |
RDNSS fe80::2e0:70ff:fe86:cebb {}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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