This topic describes how to configure IPv6 addresses for Linux Elastic Compute Service (ECS) instances. IPv6 addresses can be manually or automatically configured. We recommend that you use an appropriate tool to automatically configure IPv6 addresses.

Automatically configure IPv6 addresses

The ecs-util-ipv6 tool can be used to configure IPv6 addresses for instances that are already assigned IPv6 addresses and clear IPv6 configurations for instances that are not assigned IPv6 addresses.

The following table lists the download URLs for the ecs-util-ipv6 tool.
Series Distribution Download URL
Red Hat Enterprise Linux (RHEL)
  • CentOS 5, CentOS 6, CentOS 7, and CentOS 8
  • Red Hat 5, Red Hat 6, and Red Hat 7
  • Anolis OS
  • Fedora
  • Alibaba Cloud Linux 2/3
Download URL
Debian
  • Ubuntu 14, Ubuntu 16, Ubuntu 18, and Ubuntu 20
  • Debian 8, Debian 9, Debian 10, and Debian 11
Download URL
SUSE Linux Enterprise Server (SLES)
  • SUSE 11, SUSE 12, and SUSE 15
  • openSUSE 15 and openSUSE 42
Download URL
FreeBSD FreeBSD 11 Download URL
The ecs-util-ipv6 tool has the following limits:
  • The ecs-util-ipv6 tool applies only to ECS instances located in virtual private clouds (VPCs) and depends on instance metadata. Before you use this tool, make sure that the network service is not disabled and that outbound access to 100.100.100.200 is allows on port 80. For more information, see Overview of ECS instance metadata.
  • When the ecs-util-ipv6 tool runs, network interface controllers (NICs) and the network service are restarted. This may cause a brief network interruption. Proceed with caution.
Download an appropriate version of the ecs-util-ipv6 tool to your instance. Run the following commands to grant the execute permissions on the tool and run the tool as an administrator:
chmod +x ./ecs-utils-ipv6
./ecs-utils-ipv6
Notice If your instance uses a Ubuntu 14 public image, you must restart the instance after you run the preceding commands to make the configurations take effect. For more information, see Reboot the instance.

If your instance is already assigned an IPv6 address, the IPv6 address is automatically configured. Otherwise, the existing IPv6 address configurations are automatically cleared.

Command parameters:
ecs-utils-ipv6 --help           # show usage
ecs-utils-ipv6 --version        # show version
ecs-utils-ipv6                  # auto config all dev ipv6
ecs-utils-ipv6 --static [dev] [ip6s] [prefix_len] [gw6] # config dev static ipv6
e.g. ecs-utils-ipv6 --static eth0
       ecs-utils-ipv6 --static eth0 xxx::x1 64 xxx::x0
       ecs-utils-ipv6 --static eth0 "xxx::x1 xxx:x2 xxx:x3" 64 xxx::x0
ecs-utils-ipv6 --enable         # enable ipv6
ecs-utils-ipv6 --disable        # disable ipv6
You can enable, disable, or manually configure an IPv6 address or have an IPv6 address automatically configured. By default, an IPv6 address is automatically configured.
./ecs-utils-ipv6                 #By default, no parameter settings are required. Multiple IPv6 addresses are automatically configured for multiple NICs.
./ecs-utils-ipv6 --enable    #Enable IPv6.
./ecs-utils-ipv6 --disable    #Disable IPv6.
./ecs-utils-ipv6 --static <dev>      #Have an IPv6 address automatically configured for an NIC.
./ecs-utils-ipv6 --static <dev> <ip6s> <prefix_len> <gw6>     #Manually configure one or more IPv6 addresses for NICs. Separate the addresses with spaces and enclose each address in double quotation marks (" ").
If you want to configure IPv6 addresses for multiple instances at a time, we recommend that you use Cloud Assistant or user data to configure a script that automates the configuration process. For more information, see Cloud Assistant and Prepare user data. The following sample script is a Bash shell script that is used to configure IPv6 addresses for an instance that runs a Red Hat Enterprise Linux (RHEL) operating system:
#!/bin/sh
install_dir=/usr/sbin
install_path="$install_dir"/ecs-utils-ipv6
if [ ! -f "$install_path" ]; then
    tool_url="http://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/ipv6/rhel/ecs-utils-ipv6"
    # download the tool
    if ! wget "$tool_url" -O "$install_path"; then
        echo "[Error] download tool failed, code $?"
        exit "$?"
    fi
fi
# chmod the tool
if ! chmod +x "$install_path"; then
    echo "[Error] chmod tool failed, code $?"
    exit "$?"
fi
# run the tool
"$install_path"

Manually configure IPv6 addresses for an instance that runs an Alibaba Cloud Linux 2 or 3 operating system

Perform the following steps to manually configure IPv6 addresses for an Alibaba Cloud Linux instance.

  1. Connect to the instance. For more information, see Connect to a Linux instance by using password authentication.
  2. Check whether IPv6 is enabled for your instance.
    Note IPv6 is disabled in Alibaba Cloud Linux 2 images of the aliyun_2_1903_64_20G_alibase_20190829.vhd version and earlier. By default, IPv6 is enabled in Alibaba Cloud Linux 2 images of the aliyun_2_1903_x64_20G_alibase_20200221.vhd version and later.
    Run the ip addr | grep inet6 or ifconfig | grep inet6 command.
    • If the command output contains inet6 information, IPv6 is enabled for your instance. You can skip Step 3 and proceed to Step 4.
    • If the command output does not contain inet6 information, IPv6 is not enabled for your instance. Perform the following steps to enable IPv6.
  3. Enable IPv6.
    IPv6 can be temporarily or permanently enabled. If IPv6 is temporarily enabled, it becomes disabled when your instance is stopped or restarted. If IPv6 is permanently enabled, it remains enabled regardless of the instance state. Temporarily or permanently enable IPv6 based on your business requirements.
    • Temporarily enable IPv6.
      1. Go to the /etc/systemd/network/ directory.
        cd /etc/systemd/network/
      2. Run the ls command to check the .network file in the preceding directory.

        In this example, the 50-dhcp.network file is used.

      3. Modify the 50-dhcp.network file.
        vi /etc/systemd/network/50-dhcp.network
      4. Press the I key to enter the insert mode.
        Change the information below [Network] to DHCP=yes.
        Note If the Name parameter is set to eth*, IP addresses and routes on all network interfaces are configured through DHCP. To have only a specific network interface configured through DHCP, change the value of the Name parameter to the network interface. For example, change the value of Name to eth0 so that only the eth0 network interface is configured through DHCP. For more information about network, visit systemd.network.
        [Match]
        Name=eth*
        
        [Network]
        DHCP=yes

        After you make the change, press the Esc key, enter :wq, and then press the Enter key to save the change and exit.

      5. Enable IPv6 for all NICs or a specific NIC based on your business requirements.
        • Enable IPv6 for all NICs.
          sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
          sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0
        • Enable IPv6 for a specific NIC. In this example, the eth0 NIC is used.
          sudo sysctl -w net.ipv6.conf.eth0.disable_ipv6=0
        • Restart the systemd-networkd service to make the configurations take effect.
          sudo systemctl restart systemd-networkd
    • Permanently enable IPv6.
      1. Modify the /etc/sysctl.conf file.
        vi /etc/sysctl.conf
      2. Press the I key to enter the edit mode. Use one of the following methods to modify the file:
        • Delete the following configurations:
          net.ipv6.conf.all.disable_ipv6 = 1
          net.ipv6.conf.default.disable_ipv6 = 1
          net.ipv6.conf.lo.disable_ipv6 = 1
        • To enable IPv6 for all NICs, make the following modification:
          net.ipv6.conf.all.disable_ipv6 = 0
          net.ipv6.conf.default.disable_ipv6 = 0
          net.ipv6.conf.lo.disable_ipv6 = 0
          To enable IPv6 for a specific NIC, set the disable_ipv6 parameter that corresponds to the NIC to 0. In this example, the eth0 NIC is used.
          net.ipv6.conf.eth0.disable_ipv6 = 0

          After you make the modification, press the Esc key, enter :wq, and then press the Enter key to save the modification and exit.

      3. Check whether the configurations in the /etc/sysctl.conf file are consistent with those in the /etc/sysctl.conf file in the initial RAM file system (initramfs).
        diff -u /etc/sysctl.conf <(lsinitrd -f /etc/sysctl.conf)
        Note Alibaba Cloud Linux 2 has an initramfs configured. If the configurations in the /etc/sysctl.conf file in the initramfs are inconsistent with those in the /etc/sysctl.conf file, the system may accept the file in the initramfs.
      4. If the two files are inconsistent, run the following command to generate a new initramfs:
        sudo dracut -v -f
      5. Restart the instance.
        reboot
      6. Run the ifconfig command to check whether IPv6 is enabled.
        If IPv6 is enabled, the following network configurations are displayed:
        inet6 <Unicast address starting with fe80::>
        inet6 <IPv6 address of ECS instance>
  4. Manually configure IPv6 addresses.
    1. Run the vi /etc/sysconfig/network-scripts/ifcfg-<NIC identifier> command to open the configuration file of an NIC. Example command: vi /etc/sysconfig/network-scripts/ifcfg-eth0. Replace eth0 in the command with the actual identifier of your NIC. Add the following configurations to the file based on your business requirements:
      DHCPV6C=yes
      IPV6INIT=yes

      Save the modification and exit.

    2. Restart the instance.
      reboot

Manually configure IPv6 addresses for an instance that runs an operating system of another series

Perform the following steps to manually configure IPv6 addresses for an instance that runs an operating system of another series, such as CentOS, Debian, Ubuntu, or Fedora.

  1. Connect to the instance. For more information, see Connect to a Linux instance by using password authentication.
  2. Check whether IPv6 is enabled for your instance.
    Note By default, IPv6 is enabled on CentOS 8, Debian 10 and later, Ubuntu 18 and later.
    Run the ip addr | grep inet6 or ifconfig | grep inet6 command.
    • If the command output contain inet6 information, IPv6 is enabled for your instance. You can skip Step 3 and proceed to Step 4.
    • If the command output does not contain inet6 information, IPv6 is not enabled for your instance. Perform the following steps to enable IPv6.
  3. Enable IPv6.
    Operating system Procedure
    CentOS 6
    1. Run the vi /etc/modprobe.d/disable_ipv6.conf command and change the value of options ipv6 disable to 0. Then, save the modification and exit.
    2. Run the vi /etc/sysconfig/network command and change the value of NETWORKING_IPV6 to yes. Then, save the modification and exit.
    3. Run the following commands:
      modprobe ipv6 -r
      modprobe ipv6
    4. Run the lsmod | grep ipv6 command. If IPv6 is enabled, the following information is displayed in the command output:
      ipv6                  xxxxx  8
      Note The parameter value in the third column cannot be 0. Otherwise, you must configure IPv6 again.
    5. Run the vi /etc/sysctl.conf command and make the following modification:
      #net.ipv6.conf.all.disable_ipv6 = 1
      #net.ipv6.conf.default.disable_ipv6 = 1
      #net.ipv6.conf.lo.disable_ipv6 = 1
      
      net.ipv6.conf.all.disable_ipv6 = 0
      net.ipv6.conf.default.disable_ipv6 = 0
      net.ipv6.conf.lo.disable_ipv6 = 0

      Save the modification and exit.

    6. Run the sysctl -p command to make the modification take effect.
    CentOS 7
    1. Run the vi /etc/modprobe.d/disable_ipv6.conf command and change the value of options ipv6 disable to 0. Then, save the modification and exit.
    2. Run the vi /etc/sysconfig/network command and change the value of NETWORKING_IPV6 to yes. Then, save the modification and exit.
    3. Run the vi /etc/sysctl.conf command and make the following modification:
      #net.ipv6.conf.all.disable_ipv6 = 1
      #net.ipv6.conf.default.disable_ipv6 = 1
      #net.ipv6.conf.lo.disable_ipv6 = 1
      
      net.ipv6.conf.all.disable_ipv6 = 0
      net.ipv6.conf.default.disable_ipv6 = 0
      net.ipv6.conf.lo.disable_ipv6 = 0

      Save the modification and exit.

    4. Run the sysctl -p command to make the modification take effect.
    Debian 8 and Debian 9
    1. Run the vi /etc/default/grub command and delete ipv6.disable=1. Then, save the modification and exit.
    2. Run the vi /boot/grub/grub.cfg command and delete ipv6.disable=1. Then, save the modification and exit.
    3. Restart the instance.
    4. Run the vi /etc/sysctl.conf command and make the following modification:
      #net.ipv6.conf.all.disable_ipv6 = 1
      #net.ipv6.conf.default.disable_ipv6 = 1
      #net.ipv6.conf.lo.disable_ipv6 = 1
      
      net.ipv6.conf.all.disable_ipv6 = 0
      net.ipv6.conf.default.disable_ipv6 = 0
      net.ipv6.conf.lo.disable_ipv6 = 0

      Save the modification and exit.

    5. Run the sysctl -p command to make the modification take effect.
    • Ubuntu 14 and Ubuntu 16
    • openSUSE 42
      Note In openSUSE 42, after IPv6 is enabled, IPv6 addresses are automatically obtained and do not need to be manually configured.
    1. Run the vi /etc/sysctl.conf command and make the following modification:
      #net.ipv6.conf.all.disable_ipv6 = 1
      #net.ipv6.conf.default.disable_ipv6 = 1
      #net.ipv6.conf.lo.disable_ipv6 = 1
      
      net.ipv6.conf.all.disable_ipv6 = 0
      net.ipv6.conf.default.disable_ipv6 = 0
      net.ipv6.conf.lo.disable_ipv6 = 0

      Save the modification and exit.

    2. Run the sysctl -p command to make the modification take effect.
    FreeBSD 11
    1. Run the vi /etc/rc.conf command and add ipv6_activate_all_interfaces="YES". Then, save the modification and exit.
    2. Run the /etc/netstart restart command to restart the network service.
    SUSE 11 and SUSE 12
    Note In SUSE 11 and 12, after IPv6 is enabled, IPv6 addresses are automatically obtained and do not need to be manually configured.
    1. Run the vi /etc/modprobe.d/50-ipv6.conf command and delete install ipv6 /bin/true. Then, save the modification and exit.
    2. Run the vi /etc/sysctl.conf command and make the following modification:
      #net.ipv6.conf.all.disable_ipv6 = 1
      #net.ipv6.conf.default.disable_ipv6 = 1
      #net.ipv6.conf.lo.disable_ipv6 = 1
      
      net.ipv6.conf.all.disable_ipv6 = 0
      net.ipv6.conf.default.disable_ipv6 = 0
      net.ipv6.conf.lo.disable_ipv6 = 0

      Save the modification and exit.

    3. Run the sysctl -p command to make the modification take effect.
  4. View the IPv6 addresses assigned to your instance.
    You can view the IPv6 address assigned to your instance by using the ECS console or instance metadata.
    • ECS console: For more information about how to view the IPv6 address assigned to an instance in the ECS console, see Step 2: Assign an IPv6 address.
    • Instance metadata: You can view the IPv6 address by using the following metadata items. For more information, see Overview of ECS instance metadata.
      • IPv6 address: network/interfaces/macs/[mac]/ipv6s
      • IPv6 gateway: network/interfaces/macs/[mac]/ipv6-gateway
      • vSwitch IPv6 CIDR block: network/interfaces/macs/[mac]/vswitch-ipv6-cidr-block
  5. Manually configure IPv6 addresses.
    Operating system Procedure
    • CentOS 6 and CentOS 7
    • Red Hat 6 and Red Hat 7
    • Almalinux
    • Rocky Linux
    In this example, centos_6_10_x64_20G_alibase_20201120.vhd and centos_7_9_x64_20G_alibase_20211227.vhd are used.
    1. Run the vi /etc/sysconfig/network-scripts/ifcfg-<NIC identifier> command to open the configuration file of an NIC. Example command: vi /etc/sysconfig/network-scripts/ifcfg-eth0. Replace eth0 in the command with the actual identifier of your NIC. Add the following configurations to the file based on your business requirements:
      DHCPV6C=yes
      IPV6INIT=yes

      Save the modification and exit.

    2. Run the reboot command to restart the instance.
    CentOS 8
    In this example, centos_8_5_x64_20G_alibase_20211228.vhd is used.
    1. Check whether the NIC configuration file contains the IPV6INIT=yes and DHCPV6C=yes configurations. If yes, proceed to Step 2. If not, add the configurations to the file.
      vi /etc/sysconfig/network-scripts/ifcfg-eth0
      In this example, eth0 is used. You must replace it with the actual identifier of your NIC. Save the modification and exit.
    2. Disable the ability of cloud-init to modify the NIC files in the /etc/sysconfig/network-scripts/ directory.
      Note Assigned IPv6 addresses do not need to be manually configured, but they may be lost when the instance is restarted. Therefore, the ability of cloud-init to modify NIC files must be disabled.
      1. Run the vi /etc/cloud/cloud.cfg command to open the NIC configuration file.
        vi /etc/cloud/cloud.cfg
      2. Add the following information before Example datasource config.
        network:
          config: disabled

        Save the modification and exit.

    3. Run the reboot command to restart the instance.
    Ubuntu 14
    In this example, ubuntu_14_0405_64_20G_alibase_20170824.vhd is used.
    1. Run the vi /etc/sysctl.conf command to open the NIC configuration file. Make the following modification:
      #net.ipv6.conf.all.disable_ipv6 = 1
      #net.ipv6.conf.default.disable_ipv6 = 1
      #net.ipv6.conf.lo.disable_ipv6 = 1
      net.ipv6.conf.all.disable_ipv6 = 0
      net.ipv6.conf.default.disable_ipv6 = 0
      net.ipv6.conf.lo.disable_ipv6 = 0

      Save the modification and exit.

    2. Run the vi /etc/network/interfaces command to open the NIC configuration file. Add the following information to the file based on your business requirements:
      iface eth0 inet6 dhcp
      In this example, eth0 is used. You must replace it with the actual identifier of your NIC. Save the modification and exit.
    3. Run the reboot command to restart the instance.
    • Ubuntu 16
    • Debian 8, Debian 9, Debian 10, and Debian 11
    In this example, debian_9_13_x64_20G_alibase_20211227.vhd, debian_10_11_x64_20G_alibase_20211227.vhd, debian_11_2_x64_20G_alibase_20211227.vhd, and ubuntu_16_04_x64_20G_alibase_20211028.vhd are used.
    1. Run the vi /etc/network/interfaces command to open the NIC configuration file. Add the following information to the file based on your business requirements:
      iface eth0 inet6 dhcp
      In this example, eth0 is used. You must replace it with the actual identifier of your NIC. Save the modification and exit.
    2. Run the reboot command to restart the instance.
    Ubuntu 18 and Ubuntu 20
    In this example, ubuntu_18_04_x64_20G_alibase_20211227.vhd and ubuntu_20_04_x64_20G_alibase_20211227.vhd are used.
    1. Disable the ability of cloud-init to modify the NIC files in the /etc/sysconfig/network-scripts/ directory.
      Note Assigned IPv6 addresses do not need to be manually configured, but they may be lost when the instance is restarted. Therefore, the ability of cloud-init to modify NIC files must be disabled.
      1. Run the vi /etc/cloud/cloud.cfg command to open the NIC configuration file.
        vi /etc/cloud/cloud.cfg
      2. Add the following information before Example datasource config.
        network:
          config: disabled

        Save the modification and exit.

    2. Run the reboot command to restart the instance.
    • Anolis OS 7.9 and Anolis OS 8.4
    • CentOS Stream
    • Fedora
    In this example, anolisos_7_9_x64_20G_rhck_alibase_20220110.vhd, anolisos_8_4_x64_20G_rhck_alibase_20211008.vhd, centos_stream_8_x64_20G_alibase_20211227.vhd, and fedora_34_1_x64_20G_alibase_20211028.vhd are used.
    1. Check whether the NIC configuration file contains the IPV6INIT=yes and DHCPV6C=yes configurations. If yes, no further operations are required. If not, add the configurations to the file.
      vi /etc/sysconfig/network-scripts/ifcfg-eth0
      In this example, eth0 is used. You must replace it with the actual identifier of your NIC. Save the modification and exit.
    2. Run the reboot command to restart the instance.
    FreeBSD 11 In this example, freebsd_11_4_x64_30G_alibase_20210319.vhd is used.
    1. Run the vi /etc/rc.conf command to open the NIC configuration file. Add the following information to the file based on your business requirements:
      ipv6_enable="YES"
      ipv6_ifconfig_vtnet0="<IPv6 address> <Subnet prefix length>"
    2. Make the following modification in the file. Save the modification and exit.
      ip6addrctl_enable="YES"
      ipv6_activate_all_interfaces="YES"
      ipv6_network_interfaces="auto"
      After the modification is complete, the configuration file contains the following content:
      hostname="Aliyun"
      sshd_enable="YES"
      dumpdev="NO"
      ipv6_enable="YES"
      ip6addrctl_enable="YES"
      ip6addrctl_policy="ipv4_prefer"
      ipv6_activate_all_interfaces="YES"
      ipv6_network_interfaces="auto"
      ifconfig_lo0="inet 127.0.0.1      netmask 255.0.0.0"
      ifconfig_vtnet0="inet 192.168.XX.XX netmask 255.255.255.0"
      ipv6_ifconfig_vtnet0="2001:XXXX:4:4:4:4:4:4 prefixlen 64"
      defaultrouter="192.168.XX.XX"
      hostname="freebsd"
    3. Run the reboot command to restart the instance.