How do I enable IPv6 in RHEL 7.4 on Amazon EC2
To configure DHCPv6 on RHEL 7.4 or CentOS 7
- Connect to your instance using the instance's public IPv4 address.
Using a text editor of your choice, create a custom file, for example:
Add the following lines to your file, and save your changes:
network: version: 1 config: - type: physical name: eth0 subnets: - type: dhcp6
Reboot your instance.
Reconnect to your instance and use the ifconfig command to verify that the IPv6 address is configured on the network interface.
I found a good solution to this. I've been using terraform to launch and do initial configuration of my instances using cloud-init user-data, and the following EC2 user-data file works well for me:
#cloud-config preserve_hostname: false hostname: centos-01 fqdn: centos-01.example.com manage_etc_hosts: true write_files: - path: /etc/cloud/cloud.cfg.d/99-custom-networking.cfg owner: root:root permissions: 0600 content: | network: version: 1 config: - type: physical name: eth0 subnets: - type: dhcp - type: dhcp6 power_state: mode: reboot delay: now message: Rebooting post-config timeout: 30 condition: True
The important parts of this config are the
write_files section, which installs the appropriate cloud-init config to enable IPv6, and then
power_state, which triggers an immediate post-config reboot, which then applies the network config changes.
After reboot, this is what the network config looks like:
[[email protected] ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0 # Created by cloud-init on instance boot automatically, do not edit. # BOOTPROTO=dhcp DEVICE=eth0 DHCPV6C=yes IPV6INIT=yes IPV6_AUTOCONF=no ONBOOT=yes TYPE=Ethernet USERCTL=no
I'm happy with the solution, although I'm not entirely sure why I couldn't simply specify the network config in my user-data directly rather than having to write it to a file and reboot. At any rate, this works and is rather painless.