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.
- Download the ecs-util-ipv6 tool to a specified system. Run the following command to download the tool to CentOS:
wget https://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/ipv6/rhel/ecs-utils-ipv6
The following table lists the download URLs of the ecs-util-ipv6 tool for different operating systems.Series Distribution Download URL RHEL - CentOS 5/6/7/8
- Red Hat 5/6/7
- Anolis OS
- Fedora
- Alibaba Cloud Linux 2/3
Download URL Debian - Ubuntu 14/16/18/20
- Debian/8/9/10/11
Download URL SLES - SUSE 11/12/15
- OpenSUSE 15/42
Download URL FreeBSD FreeBSD 11 Download URL Note 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 enabled and that outbound access to 100.100.100.200 is allowed 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.
- 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
- Optional: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.
- You can run the following commands to 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 <NIC name> #Have an IPv6 address automatically configured for an NIC. ./ecs-utils-ipv6 --static <NIC name> <IPv6 address> <Subnet prefix length> <IPv6 gateway> #Manually configure one or more IPv6 addresses for NICs. Separate the addresses with spaces and enclose each address in double quotation marks (" ").
The <NIC name>, <IPv6 address>, <Subnet prefix length>, and <IPv6 gateway> fields are variables. Replace them with your actual ones.
- 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 Overview and Overview of ECS instance 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.
- Connect to the instance. For more information, see Connect to a Linux instance by using a password.
- 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 thealiyun_2_1903_x64_20G_alibase_20200221.vhd
version and later.Run theip addr | grep inet6
orifconfig | 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.
- If the command output contains
- 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.
- Run the following command to go to the /etc/systemd/network/ directory:
cd /etc/systemd/network/
- Run the
ls
command to check the.network
file in the preceding directory.In this example, the
50-dhcp.network
file is used. - Modify the 50-dhcp.network file.
vi /etc/systemd/network/50-dhcp.network
- Press the I key to enter the edit mode.
Change the information below
[Network]
toDHCP=yes
.Note If theName
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 theName
parameter to the network interface. For example, change the value ofName
to eth0 so that only theeth0
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. - Run the following commands to 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
- Enable IPv6 for all NICs.
- Run the following command to go to the /etc/systemd/network/ directory:
- Permanently enable IPv6.
- Modify the
/etc/sysctl.conf
file.vi /etc/sysctl.conf
- 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:
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.all.disable_ipv6 = 0 net.ipv6.conf.default.disable_ipv6 = 0 net.ipv6.conf.lo.disable_ipv6 = 0
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.
- Delete the following configurations:
- 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. - If the two files are inconsistent, run the following command to generate a new initramfs:
sudo dracut -v -f
- Restart the instance.
reboot
- 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>
- Modify the
- Temporarily enable IPv6.
- Manually configure IPv6 addresses.
- Run the
vi /etc/sysconfig/network-scripts/ifcfg-eth0
command to open the configuration file of an NIC. In the command, eth0 indicates the identifier of a NIC. 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.
- Restart the instance.
reboot
- Run the
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.
- Connect to the instance. For more information, see Connect to a Linux instance by using a password.
- Check whether IPv6 is enabled for your instance. Note By default, IPv6 is enabled on CentOS 8, Debian 10 and later, and Ubuntu 18 and later.
ip addr | grep inet6
orifconfig | 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.
- If the command output contains
- Enable IPv6.
Operating system Procedure CentOS 6 - Run the
vi /etc/modprobe.d/disable_ipv6.conf
command and change the value ofoptions ipv6 disable
to0
. Then, save the modification and exit. - Run the
vi /etc/sysconfig/network
command and change the value ofNETWORKING_IPV6
toyes
. Then, save the modification and exit. - Run the following commands:
modprobe ipv6 -r modprobe ipv6
- 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. - 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.
- Run the
sysctl -p
command to make the modification take effect.
CentOS 7 - Run the
vi /etc/modprobe.d/disable_ipv6.conf
command and change the value ofoptions ipv6 disable
to0
. Then, save the modification and exit. - Run the
vi /etc/sysconfig/network
command and change the value ofNETWORKING_IPV6
toyes
. Then, save the modification and exit. - 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.
- Run the
sysctl -p
command to make the modification take effect.
Debian 8/9 - Run the
vi /etc/default/grub
command and deleteipv6.disable=1
. Then, save the modification and exit. - Run the
vi /boot/grub/grub.cfg
command and deleteipv6.disable=1
. Then, save the modification and exit. - Restart the instance.
- 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.
- Run the
sysctl -p
command to make the modification take effect.
- Ubuntu 14/16
- OpenSUSE 42
Note In openSUSE 42, after IPv6 is enabled, IPv6 addresses are automatically obtained and do not need to be manually configured.
- 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.
- Run the
sysctl -p
command to make the modification take effect.
FreeBSD 11 - Run the
vi /etc/rc.conf
command and addipv6_activate_all_interfaces="YES"
. Then, save the modification and exit. - Run the
/etc/netstart restart
command to restart the network service.
SUSE 11/12 Note In SUSE 11 and 12, after IPv6 is enabled, IPv6 addresses are automatically obtained and do not need to be manually configured.- Run the
vi /etc/modprobe.d/50-ipv6.conf
command and deleteinstall ipv6 /bin/true
. Then, save the modification and exit. - 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.
- Run the
sysctl -p
command to make the modification take effect.
- Run the
- 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
- Manually configure IPv6 addresses.
Operating system Procedure - CentOS 6/7
- Red Hat 6/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.- Run the
vi /etc/sysconfig/network-scripts/ifcfg-eth0
command to open the configuration file of an NIC. In the command,eth0
indicates the identifier of a NIC. Replace eth0 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.
- Run the
reboot
command to restart the instance.
CentOS 8 In this example, centos_8_5_x64_20G_alibase_20211228.vhd is used.- Check whether the NIC configuration file contains the
IPV6INIT=yes
andDHCPV6C=yes
configurations. If yes, proceed to Step 2. If not, add the configurations to the file.
In this example,vi /etc/sysconfig/network-scripts/ifcfg-eth0
eth0
is used. You must replace it with the actual identifier of your NIC. Save the modification and exit. - 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.- Run the
vi /etc/cloud/cloud.cfg
command to open the NIC configuration file.vi /etc/cloud/cloud.cfg
- Add the following information before
Example datasource config
:network: config: disabled
Save the modification and exit.
- Run the
- Run the
reboot
command to restart the instance.
Ubuntu 14 In this example, ubuntu_14_0405_64_20G_alibase_20170824.vhd is used.- 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.
- 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:
In this example,iface eth0 inet6 dhcp
eth0
is used. You must replace it with the actual identifier of your NIC. Save the modification and exit. - Run the
reboot
command to restart the instance.
- Ubuntu 16
- Debian 8/9/10/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.- 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:
In this example,iface eth0 inet6 dhcp
eth0
is used. You must replace it with the actual identifier of your NIC. Save the modification and exit. - Run the
reboot
command to restart the instance.
Ubuntu 18/20 In this example, ubuntu_18_04_x64_20G_alibase_20211227.vhd and ubuntu_20_04_x64_20G_alibase_20211227.vhd are used.- 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.- Run the
vi /etc/cloud/cloud.cfg
command to open the NIC configuration file.vi /etc/cloud/cloud.cfg
- Add the following information before
Example datasource config
:network: config: disabled
Save the modification and exit.
- Run the
- Run the
reboot
command to restart the instance.
- Anolis OS 7.9/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. - Check whether the NIC configuration file contains the
IPV6INIT=yes
andDHCPV6C=yes
configurations. If yes, no further operations are required. If not, add the configurations to the file.
In this example,vi /etc/sysconfig/network-scripts/ifcfg-eth0
eth0
is used. You must replace it with the actual identifier of your NIC. Save the modification and exit. - Run the
reboot
command to restart the instance.
FreeBSD 11 In this example, freebsd_11_4_x64_30G_alibase_20210319.vhd is used. - 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>"
- Make the following modification in the file. Save the modification and exit.
After the modification is complete, the configuration file contains the following content:ip6addrctl_enable="YES" ipv6_activate_all_interfaces="YES" ipv6_network_interfaces="auto"
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"
- Run the
reboot
command to restart the instance.