In my specific case, my router leases IPv6 addresses to my VMs running in my server (in premisses) via DHCP and so... I don't need to hardcode or generate any IP configuration. I just need to inform a DNS server about the dynamically generated addresses.
The snippet below (from my cloud-config
script) creates /etc/sysctl.conf
so that it enables IPv6 on a VM running Centos7.
It also creates a shell script which updates the current IPv6 address onto FreeDNS every 15mins, requiring the FQDN and a DDNS key which can be obtained when you setup a AAAA record marked as dynamic.
local fqdn="vm.example.com"
local ddnspasswd='obtain-ddns-key-at-dns.he.net'
cat > user-data <<EOF
# configure IPv6
write_files:
- content: |
net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
path: /etc/sysctl.conf
owner: root:root
permissions: 0600
- content: |
#!/bin/bash
function ddns_update_ipv4 {
local fqdn="${fqdn}"
local ddnspasswd="${ddnspasswd}"
/usr/bin/curl -4 "https://dyn.dns.he.net/nic/update" -d "hostname=\${fqdn}" -d "password=\${ddnspasswd}" >> /dev/null 2>&1
local STATUS=\$?
if [[ \$STATUS -ne 0 ]]; then
echo "IPv4 DNS update failed, return code: \$STATUS" >> /var/log/ddns.log
return 1
fi
return 0
}
function ddns_update_ipv6 {
local fqdn="${fqdn}"
local ddnspasswd="${ddnspasswd}"
/usr/bin/curl -6 "https://dyn.dns.he.net/nic/update" -d "hostname=\${fqdn}" -d "password=\${ddnspasswd}" >> /dev/null 2>&1
local STATUS=\$?
if [[ \$STATUS -ne 0 ]]; then
echo "IPv6 DNS update failed, return code: \$STATUS" >> /var/log/ddns.log
return 1
fi
return 0
}
ddns_update_ipv6
path: /sbin/ddns-update
owner: root:root
permissions: 0500
# Update IPv6 on FreeDNS (http://dns.he.net/) every 15 mins
runcmd:
- systemctl stop network && systemctl start network
- echo "0,15,30,45 * * * * /sbin/ddns-update" | tee -a /etc/crontab
- crontab -u root /etc/crontab
EOF