How to configure IPv6 on Amazon EC2 instance running CentOS 7

Problem

According to the IPv6 migration guide:

RHEL 7.4 and CentOS 7 and later use cloud-init to configure your network interface and generate the /etc/sysconfig/network-scripts/ifcfg-eth0 file. You can create a custom cloud-init configuration file to enable DHCPv6, which generates an ifcfg-eth0 file with settings that enable DHCPv6 after each reboot.

However after rebooting the instance it looses IPv6 address and IPv6 connectivity.

It appears that this is caused by cloud-init package, see this bug report for details. There are two similar bugs reported in CentOS bug tracker: #14760 and #15833.

According to EC2 cloud-init guide, cloud-init only runs during first launch of the instance. But every time I reboot the instance, I see the following messages in the /var/log/cloud-init.log.

2019-10-27 14:18:18,575 - __init__.py[DEBUG]: Update datasource metadata and network config due to events: New instance first boot
2019-10-27 14:18:20,515 - __init__.py[DEBUG]: Update datasource metadata and network config due to events: System boot

That indicates that cloud-init doesn’t detect first launch properly and runs on every reboot. Because of that it regenerates /etc/sysconfig/network-scripts/ifcfg-eth0 and setting IPV6_AUTOCONF=yes is not preserved or generated.

Solution

  1. Follow until step 5 in Migrating to IPv6 guide.
  2. Add cloud-init configuration script according to RHEL 7.4 / CentOS 7 instructions.
  3. Connect to your instance via SSH.
  4. Edit /etc/rc.local

 file and add the lines below.
    
    ###############################################################################
    # Workaround for issue with 'cloud-init' and IPv6 connectivity
    # See https://bugs.centos.org/view.php?id=15833
    # -----------------------------------------------------------------------------
    echo IPV6_AUTOCONF=yes >> /etc/sysconfig/network-scripts/ifcfg-eth0
    systemctl restart network
    ###############################################################################
    
  5. Save (:wq) and exit.
  6. Add executable permissions to rc.local file.
    
    $ chmod +x /etc/rc.local
    
  7. Reboot the instance.
  8. Ping ipv6.google.com.
  9. 
    $ ping6 ipv6.google.com

PING ipv6.google.com(fra16s12-in-x0e.1e100.net (2a00:1450:4001:818::200e)) 56 data bytes
    64 bytes from fra16s12-in-x0e.1e100.net (2a00:1450:4001:818::200e): icmp_seq=1 ttl=51 time=0.449 ms
    64 bytes from fra16s12-in-x0e.1e100.net (2a00:1450:4001:818::200e): icmp_seq=2 ttl=51 time=0.464 ms
    
  10. Ping your instance IPv6 address from outside, for example from IPv6now website.

You May Also Like

Leave a Reply

(optional)

This site uses Akismet to reduce spam. Learn how your comment data is processed.