Centos – cloud-init can’t set up ipv6

centoscloud-initipv6ovh

I've bought a Public Cloud VPS from OVH and trying to set up ipv6.
Also I've found a tutorial on how to set up ipv6 in their documentation. It works until I reboot the VPS.

In this tutorial they want me to update this file /etc/sysconfig/network-scripts/ifcfg-eth0 but inside that file it says "Created by cloud-init on instance boot automatically, do not edit". I've also tried to contact OVH's support, but they responded that they can't help me with that and suggested to ask here.

Can somebody help me with this? I've never worked with cloud-init and don't even know where is a config that generates ifcfg-eth0.

OS: Centos7

Best Answer

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
Related Topic