Last active
April 12, 2021 00:19
-
-
Save hcooper/a5b9633755240134d407 to your computer and use it in GitHub Desktop.
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/vbash | |
# If IPv6 is working - exit. | |
/bin/ping6 -c 2 -n google.com > /dev/null | |
if [ $? == 0 ]; then | |
echo "IPv6 working." | |
exit 0; | |
fi | |
# If we have no working IPv4 connection - exit. | |
/bin/ping -c 2 -n google.com > /dev/null | |
if [ $? != 0 ]; then | |
echo "IPv4 seems down - exiting." | |
exit 1; | |
fi | |
echo "Starting config of IPv6rd" | |
source /opt/vyatta/etc/functions/script-template | |
# Get our external IPv4 address (not sure why this can't be read from the interface config, *shrug*). | |
IP4=$(curl -s ipv4.icanhazip.com) | |
if ! [[ $IP4 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
exit; | |
fi | |
# Change v4->v6rd address. | |
IP6=$(printf "2602:%02x:%02x%02x:%02x00\n" $(echo $IP4 | tr . ' ')) | |
configure | |
# Delete old IPv6RD configs, otherwise they just stack up. | |
for addr in $(show interfaces ethernet eth2 vif 2 address | grep 2602 | awk '{print $2}'); do | |
delete interfaces ethernet eth2 vif 2 address $addr; | |
done | |
for addr in $(show interfaces tunnel tun0 address | grep 2602 | awk '{print $2}'); do | |
delete interfaces tunnel tun0 address $addr; | |
done | |
delete interfaces ethernet eth2 vif 2 ipv6 | |
# It's easier to just delete + recreate the IPv6RD interface than trying to edit an existing one. | |
set interfaces tunnel tun0 6rd-prefix "2602::/24" | |
set interfaces tunnel tun0 address "$IP6::1/24" | |
set interfaces tunnel tun0 description "CenturyLink IPv6 6rd tunnel" | |
set interfaces tunnel tun0 encapsulation sit | |
set interfaces tunnel tun0 local-ip "$IP4" | |
set interfaces tunnel tun0 mtu 1472 | |
set interfaces tunnel tun0 multicast disable | |
set interfaces tunnel tun0 ttl 255 | |
set protocols static route6 '::/0' next-hop '::205.171.2.64' interface tun0 | |
set interfaces ethernet eth2 vif 2 address "$IP6::1/64" | |
set interfaces ethernet eth2 vif 2 ipv6 dup-addr-detect-transmits 1 | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert cur-hop-limit 64 | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert link-mtu 1472 | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert managed-flag false | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert max-interval 300 | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert other-config-flag false | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert prefix "$IP6::/64" autonomous-flag true | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert prefix "$IP6::/64" on-link-flag true | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert prefix "$IP6::/64" valid-lifetime 2592000 | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert reachable-time 0 | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert retrans-timer 0 | |
set interfaces ethernet eth2 vif 2 ipv6 router-advert send-advert true | |
commit | |
save | |
# If you don't do this, unionfs mounts will OOM your box. | |
configure_exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment