This topic describes how to configure an IPv6 address for a Linux instance. IPv6 addresses can be manually configured, or automatically configured by the system. We recommend that you use an appropriate tool to automatically configure IPv6 addresses.

Automatically configure an IPv6 address

The ecs-util-ipv6 tool can be used to configure IPv6 addresses for instances that are assigned IPv6 addresses, or 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
RHEL
  • CentOS 5/6/7/8
  • Red Hat 5/6/7
Download URL
Debian
  • Ubuntu 14/16
  • Debian/8/9
Download URL
SLES
  • SUSE 11/12
  • openSUSE 42
Download URL
CoreOS CoreOS 14/17 Download URL
FreeBSD FreeBSD 11 Download URL
The ecs-util-ipv6 tool has the following limits:
  • The ecs-util-ipv6 tool applies only to Elastic Compute Service (ECS) instances in virtual private clouds (VPCs) and relies on instance metadata. Before you use this tool, make sure that the network service or the relevant outbound IP port (100.100.100.200:80) is enabled. For more information, see Overview of ECS instance metadata.
  • When the ecs-util-ipv6 tool is running, network interface controllers (NICs) and the network service are restarted. As a result, your network connection may be unavailable for a period of time. Proceed with caution.
Download the tool to your system and run the following command to run the tool as an administrator:
chmod +x ./ecs-utils-ipv6
./ecs-utils-ipv6

If your ECS instance is assigned an IPv6 address, the tool automatically configures the IPv6 address. Otherwise, the tool clears the existing IPv6 address configurations.

Command line:
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. By default, the system configures an IPv6 address.
./ecs-utils-ipv6                 #By default, no parameter settings are required. The system configures multiple IPv6 addresses for multiple NICs.
./ecs-utils-ipv6 --enable    #Enable IPv6.
./ecs-utils-ipv6 --disable    #Disable IPv6.
./ecs-utils-ipv6 --static <dev>      #The system configures an IPv6 address for an NIC.
./ecs-utils-ipv6 --static <dev> <ip6s> <prefix_len> <gw6>     #Manually configure one or more IPv6 addresses for NICs. Specify multiple IPv6 addresses in double quotation marks (" ") and separate them with spaces.
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 scripts that automate the process of configuring IPv6 addresses. For more information, see Overview of Cloud Assistant and Overview of ECS instance user data. In the following script, Red Hat Enterprise Linux (RHEL) and Bash shell are used:
#!/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 an IPv6 address (Alibaba Cloud Linux 2)

IPv6 is disabled on Alibaba Cloud Linux 2 of the aliyun_2_1903_64_20G_alibase_20190829.vhd version and earlier. IPv6 is enabled by default on Alibaba Cloud Linux 2 of the aliyun_2_1903_x64_20G_alibase_20200221.vhd version and later.

Check whether IPv6 is enabled for your instance.
  1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
  2. Run the ip addr | grep inet6 or ifconfig | grep inet6 command.
    • If the inet6 related information is returned, IPv6 is enabled for your instance. You can skip this section.
    • If no inet6 related information is returned, IPv6 is not enabled for your instance. Perform the following operations to enable IPv6.

IPv6 can be temporarily or permanently enabled. If IPv6 is temporarily enabled, it becomes invalid when your instance is stopped or restarted. If IPv6 is permanently enabled, it is always enabled regardless of the instance status. You can select a configuration method based on your needs.

  • Temporarily enable IPv6
    1. Run the following command to go to the /etc/systemd/network/ directory:
      cd /etc/systemd/network/
    2. Run the ls command to check the files in the .network format in this directory.

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

    3. Modify the content of the 50-dhcp.network file.
      vi /etc/systemd/network/50-dhcp.network
    4. Press the I key to enter the edit 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 complete the modification, press the Esc key, enter :wq, and then press the Enter key to save the modification and exit the edit mode.

    5. Run the following commands to enable IPv6.
      • Enable IPv6 on all NICs.
        sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
        sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0
      • Enable IPv6 on a specific NIC. Example:
        sudo sysctl -w net.ipv6.conf.eth0.disable_ipv6=0
      • Restart the systemd-networkd service to make the configuration take effect.
        sudo systemctl restart systemd-networkd
  • Permanently enable IPv6
    1. Run the following command to 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 content:
      • 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
      • Add the following configurations:
        net.ipv6.conf.all.disable_ipv6 = 0
        net.ipv6.conf.default.disable_ipv6 = 0
        net.ipv6.conf.lo.disable_ipv6 = 0
        The following example shows the information to be entered to enable IPv6 on a specific NIC:
        net.ipv6.conf.eth0.disable_ipv6 = 0

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

    3. Run the following command to check whether the configurations in the /etc/sysctl.conf file are consistent with those in the /etc/sysctl.conf file in the initram file system (initramfs):
      diff -u /etc/sysctl.conf <(lsinitrd -f /etc/sysctl.conf)
      Note Alibaba Cloud Linux 2 has initramfs configured. If the /etc/sysctl.conf file in initramfs is inconsistent with the /etc/sysctl.conf file in IPv6 configurations, the system may accept the file in initramfs.
    4. If the two configuration files are inconsistent, run the following command to generate a new initramfs:
      sudo dracut -v -f
    5. Restart your instance.
      sudo reboot
    6. Run the ifconfig command to check whether IPv6 is enabled.
      If the following network configurations are displayed, IPv6 is enabled:
      inet6 <Unicast address starting with fe80::>
      inet6 <IPv6 address of ECS instance>
To enable IPv6 on multiple NICs, perform the following operations:
  1. Run the following command to go to the /etc/systemd/network/ directory:
    cd /etc/systemd/network/
  2. Run the ls command to check the files in the .network format in this directory.

    In this example, the 10-eth0.network file is used.

  3. Run the cp command to duplicate a configuration file. Example:
    cp 10-eth0.network 20-dhcp.network
  4. Run the following command to modify the configuration file:
    sed -i 's/^Name.*$/Name=*/g' /etc/systemd/network/20-dhcp.network
  5. Restart the systemd-networkd service to make the configuration take effect.
    sudo systemctl restart systemd-networkd

Manually configure an IPv6 address (other operating systems)

To enable IPv6 on an operating system such as CentOS, Debian, FreeBSD, openSUSE, SUSE, or Ubuntu, perform the following operations:

  1. Check whether IPv6 is enabled for your instance.
    Notice By default, IPv6 is enabled on CentOS 8, Debian 10.3, and Ubuntu 18.04.
    1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
    2. Run the ip addr | grep inet6 or ifconfig | grep inet6 command.
      • If the inet6 related information is returned, IPv6 is enabled for your instance. You can skip this section.
      • If no inet6 related information is returned, IPv6 is not enabled for your instance. Perform the following operations to enable IPv6.
  2. Enable IPv6.
    • CentOS 6
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/modprobe.d/disable_ipv6.conf command and change options ipv6 disable=1 to options ipv6 disable=0. Save the modification and exit.
      3. Run the vi /etc/sysconfig/network command and change NETWORKING_IPV6=no to NETWORKING_IPV6=yes. Save the modification and exit.
      4. Run the following commands:
        modprobe ipv6 -r
        modprobe ipv6
      5. Run the lsmod | grep ipv6 command. IPv6 is enabled if the following information is returned:
        ipv6                  xxxxx  8
        Note The parameter value in the third column cannot be 0. Otherwise, you must configure IPv6 again.
      6. Run the vi /etc/sysctl.conf command and add the following code:
        #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.

      7. Run the sysctl -p command to make the configuration take effect.
    • CentOS 7
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/modprobe.d/disable_ipv6.conf command and change options ipv6 disable=1 to options ipv6 disable=0. Save the modification and exit.
      3. Run the vi /etc/sysconfig/network command and change NETWORKING_IPV6=no to NETWORKING_IPV6=yes. Save the modification and exit.
      4. Run the vi /etc/sysctl.conf command and add the following code:
        #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 configuration take effect.
    • CoreOS 14 or 17
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /usr/share/oem/grub.cfg command and delete ipv6.disable=1. Save the modification and exit.
      3. Restart your instance.
    • Debian 8 or 9
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/default/grub command and delete ipv6.disable=1. Save the modification and exit.
      3. Run the vi /boot/grub/grub.cfg command and delete ipv6.disable=1. Save the modification and exit.
      4. Restart your instance.
      5. Run the vi /etc/sysctl.conf command and add the following code:
        #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 configuration take effect.
    • FreeBSD 11
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/rc.conf command and add ipv6_activate_all_interfaces="YES". Save the modification and exit.
      3. Run the /etc/netstart restart command to restart the network service.
    • openSUSE 42
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/sysctl.conf command and add the following code:
        #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 configuration take effect.
    • SUSE 11 or 12
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/modprobe.d/50-ipv6.conf command and delete install ipv6 /bin/true. Save the modification and exit.
      3. Run the vi /etc/sysctl.conf command and add the following code:
        #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 configuration take effect.
    • Ubuntu 14 or 16
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/sysctl.conf command and add the following code:
        #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 configuration take effect.
  3. Check the IPv6 address assigned to the instance.
    You can view the IPv6 address assigned to the instance by using the ECS console or instance metadata.
    • ECS console: For more information, see Step 2: Assign an IPv6 address.
    • Instance metadata: You can view the IPv6 address by using the following metadata. For more information, see Overview of ECS instance metadata.
      • IPv6 address: network/interfaces/macs/[mac]/ipv6s
      • IPv6 gateway: network/interfaces/macs/[mac]/ipv6-gateway
      • IPv6 vSwitch CIDR block: network/interfaces/macs/[mac]/vswitch-ipv6-cidr-block
  4. Manually configure IPv6 addresses.
    • CentOS 6, 7, or 8, or Red Hat 6 or 7
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/sysconfig/network-scripts/ifcfg-eth0 command to open the NIC configuration file. Change eth0 to the identifier of your NIC. Add the following configurations based on your needs:
        • Single IPv6 address:
          IPV6INIT=yes
          IPV6ADDR=<IPv6 address>/<Subnet prefix length>
          IPV6_DEFAULTGW=<IPv6 gateway>
        • Multiple IPv6 addresses:
          IPV6INIT=yes
          IPV6ADDR=<IPv6 address>/<Subnet prefix length>
          IPV6ADDR_SECONDARIES="<IPv6 address 1>/<Subnet prefix length> <IPv6 address 2>/<Subnet prefix length>"
          IPV6_DEFAULTGW=<IPv6 gateway>
          Note To distinguish multiple IPv6 addresses from a single one, specify a list of IPv6 addresses for the IPV6ADDR_SECONDARIES parameter. Specify multiple IPv6 addresses in double quotation marks ( " ") and separate them with spaces.
      3. Run the following command to restart the network service:
        • For operating systems other than CentOS 8: service network restart or systemctl restart network
        • For CentOS 8: nmcli c reload
    • Debian 8 or 9, or Ubuntu 14 or 16
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/network/interfaces command to open the NIC configuration file. Change eth0 to the identifier of your NIC. Add the following configurations based on your needs:
        • Single IPv6 address:
          auto eth0
          iface eth0 inet6 static
          address <IPv6 address>
          netmask <Subnet prefix length>
          gateway <IPv6 gateway>
        • Multiple IPv6 addresses:
          auto eth0
          iface eth0 inet6 static
          address <IPv6 address>
          netmask <Subnet prefix length>
          gateway <IPv6 gateway>
          
          auto eth0:0
          iface eth0:0 inet6 static
          address <IPv6 address 1>
          netmask <Subnet prefix length>
          gateway <IPv6 gateway>
          
          auto eth0:1
          iface eth0:1 inet6 static
          address <IPv6 address 2>
          netmask <Subnet prefix length>
          gateway <IPv6 gateway>
          Note To distinguish multiple IPv6 addresses from a single one, you need only to add information of more IPv6 addresses based on the same NIC identifier.
      3. Run the service network restart or systemctl restart networking command to restart the network service.
    • openSUSE 42 or SUSE Linux 11 or 12
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/sysconfig/network/ifcfg-eth0 command to open the NIC configuration file. Change eth0 to the identifier of your NIC. Add the following configurations based on your needs:
        • Single IPv6 address:
          IPADDR_0=<IPv6 address>
          PREFIXLEN_0=<Subnet prefix length>
        • Multiple IPv6 addresses:
          IPADDR_0=<IPv6 address>
          PREFIXLEN_0=<Subnet prefix length>
          
          IPADDR_1=<IPv6 address 1>
          PREFIXLEN_1=<Subnet prefix length>
          
          IPADDR_2=<IPv6 address 2>
          PREFIXLEN_2=<Subnet prefix length>
          Note To distinguish multiple IPv6 addresses from a single one, use the IPADDR_N and PREFIXLEN_N parameters to add information of more IPv6 addresses.
      3. Run the vi /etc/sysconfig/network/routes command to open the route configuration file and add the following code:
        default <IPv6 gateway> - -
      4. Run the service network restart or systemctl restart networking command to restart the network service.
    • CoreOS 14 or 17
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/systemd/network/10-eth0.network command to open the NIC configuration file. Change eth0 to the identifier of your NIC. Add the following configurations based on your needs:
        • Single IPv6 address:
          [Address]
          Address=<IPv6 address>/<Subnet prefix length>
          [Route]
          Destination=::/0
          Gateway=<IPv6 gateway>
        • Multiple IPv6 addresses:
          [Address]
          Address=<IPv6 address 1>/<Subnet prefix length>
          [Address]
          Address=<IPv6 address 2>/<Subnet prefix length>
          [Route]
          Destination=::/0
          Gateway=<IPv6 gateway>
          Note To distinguish multiple IPv6 addresses from a single one, you need only to add information of more IPv6 addresses based on the same NIC identifier.
      3. Run the systemctr restart systemd-networkd command to restart the network service.
    • FreeBSD 11
      1. Connect to your instance by using a remote terminal. For more information, see Connect to a Linux instance by using password authentication.
      2. Run the vi /etc/rc.conf command to open the NIC configuration file. Change vtnet0 to the identifier of your NIC. Add the following configurations based on your needs:
        • Single IPv6 address:
          ipv6_ifconfig_vtnet0="<IPv6 address>"
          ipv6_defaultrouter="<IPv6 gateway>"
        • Multiple IPv6 addresses:
          ipv6_ifconfig_vtnet0="<IPv6 address 1>"
          ipv6_ifconfig_vtnet0="<IPv6 address 2>"
          ipv6_defaultrouter="<IPv6 gateway>"
          Note To distinguish multiple IPv6 addresses from a single one, you need only to add information of more IPv6 addresses based on the same NIC identifier.
      3. Run the /etc/netstart restart command to restart the network service.