为 Linux VM 配置 DHCPv6Configure DHCPv6 for Linux VMs

Azure 市场中的某些 Linux 虚拟机映像默认未配置动态主机配置协议版本 6 (DHCPv6)。Some of the Linux virtual-machine images in the Azure Marketplace do not have Dynamic Host Configuration Protocol version 6 (DHCPv6) configured by default. 要支持 IPv6,必须在使用的 Linux OS 分发版中配置 DHCPv6。To support IPv6, DHCPv6 must be configured in the Linux OS distribution that you are using. 各种 Linux 分发会以不同方式配置 DHCPv6,因为它们使用不同的包。The various Linux distributions configure DHCPv6 in a variety of ways because they use different packages.

Note

Azure 市场中最新的 SUSE Linux 和 CoreOS 映像已预先配置 DHCPv6。Recent SUSE Linux and CoreOS images in the Azure Marketplace have been pre-configured with DHCPv6. 使用这些映像不需要进行额外的更改。No additional changes are required when you use these images.

本文档介绍如何启用 DHCPv6,使 Linux 虚拟机能够获取 IPv6 地址。This document describes how to enable DHCPv6 so that your Linux virtual machine obtains an IPv6 address.

Warning

不恰当地编辑网络配置文件的操作可能会使你失去 VM 的网络访问权限。By improperly editing network configuration files, you can lose network access to your VM. 建议先在非生产系统上测试配置更改。We recommended that you test your configuration changes on non-production systems. 本文中的说明已根据 Azure 市场中的最新版 Linux 映像进行测试。The instructions in this article have been tested on the latest versions of the Linux images in the Azure Marketplace. 有关详细说明,请参阅适用于你所用 Linux 版本的文档。For more detailed instructions, consult the documentation for your own version of Linux.

UbuntuUbuntu

  1. 编辑 /etc/dhcp/dhclient6.conf 文件,并添加以下行 :Edit the /etc/dhcp/dhclient6.conf file, and add the following line:

     timeout 10;
    
  2. 编辑使用以下配置的 eth0 接口的网络配置:Edit the network configuration for the eth0 interface with the following configuration:

    • 在 Ubuntu 12.04 和 14.04 上编辑 /etc/network/interfaces.d/eth0.cfg 文件 。On Ubuntu 12.04 and 14.04, edit the /etc/network/interfaces.d/eth0.cfg file.

    • 在 Ubuntu 16.04 上编辑 /etc/network/interfaces.d/50-cloud-init.cfg 文件 。On Ubuntu 16.04, edit the /etc/network/interfaces.d/50-cloud-init.cfg file.

      iface eth0 inet6 auto
          up sleep 5
          up dhclient -1 -6 -cf /etc/dhcp/dhclient6.conf -lf /var/lib/dhcp/dhclient6.eth0.leases -v eth0 || true
      
  3. 续订 IPv6 地址:Renew the IPv6 address:

    sudo ifdown eth0 && sudo ifup eth0
    

从 Ubuntu 17.10 开始,默认网络配置机制是 NETPLANBeginning with Ubuntu 17.10, the default network configuration mechanism is NETPLAN. 在安装/实例化时,NETPLAN 从以下位置的 YAML 配置文件中读取网络配置:/{lib,etc,run}/netplan/*.yaml。At install/instantiation time, NETPLAN reads network configuration from YAML configuration files at this location: /{lib,etc,run}/netplan/*.yaml.

请为配置中的每个以太网接口添加“dhcp6:true” 语句。Please include a dhcp6:true statement for each ethernet interface in your configuration. 例如:For example:

    network:
      version: 2
      ethernets:
        eno1:
          dhcp6: true

在早期启动过程中,netplan “network renderer”将配置写入“/run”,以将设备控制权移交给指定的网络守护程序。有关 NETPLAN 的参考信息,请参阅 https://netplan.io/referenceDuring early boot, the netplan “network renderer” writes configuration to /run to hand off control of devices to the specified networking daemon For reference information about NETPLAN, see https://netplan.io/reference.

DebianDebian

  1. 编辑 /etc/dhcp/dhclient6.conf 文件,并添加以下行 :Edit the /etc/dhcp/dhclient6.conf file, and add the following line:

     timeout 10;
    
  2. 编辑 /etc/network/interfaces 文件,添加以下配置 :Edit the /etc/network/interfaces file, and add the following configuration:

     iface eth0 inet6 auto
         up sleep 5
         up dhclient -1 -6 -cf /etc/dhcp/dhclient6.conf -lf /var/lib/dhcp/dhclient6.eth0.leases -v eth0 || true
    
  3. 续订 IPv6 地址:Renew the IPv6 address:

    sudo ifdown eth0 && sudo ifup eth0
    

RHEL、CentOS 和 Oracle LinuxRHEL, CentOS, and Oracle Linux

  1. 编辑 /etc/sysconfig/network 文件,添加以下参数 :Edit the /etc/sysconfig/network file, and add the following parameter:

     NETWORKING_IPV6=yes
    
  2. 编辑 /etc/sysconfig/network-scripts/ifcfg-eth0 文件,添加以下两个参数 :Edit the /etc/sysconfig/network-scripts/ifcfg-eth0 file, and add the following two parameters:

     IPV6INIT=yes
     DHCPV6C=yes
    
  3. 续订 IPv6 地址:Renew the IPv6 address:

    sudo ifdown eth0 && sudo ifup eth0
    

SLES 11 和 openSUSE 13SLES 11 and openSUSE 13

Azure 中最新的 SUSE Linux Enterprise Server (SLES) 和 openSUSE 映像已预先配置 DHCPv6。Recent SUSE Linux Enterprise Server (SLES) and openSUSE images in Azure have been pre-configured with DHCPv6. 使用这些映像不需要进行额外的更改。No additional changes are required when you use these images. 如果 VM 基于旧版或自定义的 SUSE 映像,请执行以下步骤:If you have a VM that's based on an older or custom SUSE image, do the following:

  1. 根据需要安装 dhcp-client 包:Install the dhcp-client package, if needed:

    sudo zypper install dhcp-client
    
  2. 编辑 /etc/sysconfig/network/ifcfg-eth0 文件,添加以下参数 :Edit the /etc/sysconfig/network/ifcfg-eth0 file, and add the following parameter:

     DHCLIENT6_MODE='managed'
    
  3. 续订 IPv6 地址:Renew the IPv6 address:

    sudo ifdown eth0 && sudo ifup eth0
    

SLES 12 和 openSUSE LeapSLES 12 and openSUSE Leap

Azure 中最新的 SLES 和 openSUSE 映像已预先配置 DHCPv6。Recent SLES and openSUSE images in Azure have been pre-configured with DHCPv6. 使用这些映像不需要进行额外的更改。No additional changes are required when you use these images. 如果 VM 基于旧版或自定义的 SUSE 映像,请执行以下步骤:If you have a VM that's based on an older or custom SUSE image, do the following:

  1. 编辑 /etc/sysconfig/network/ifcfg-eth0 文件,并使用以下值替换 #BOOTPROTO='dhcp4' 参数:Edit the /etc/sysconfig/network/ifcfg-eth0 file, and replace the #BOOTPROTO='dhcp4' parameter with the following value:

     BOOTPROTO='dhcp'
    
  2. 编辑 /etc/sysconfig/network/ifcfg-eth0 文件,添加以下参数 :To the /etc/sysconfig/network/ifcfg-eth0 file, add the following parameter:

     DHCLIENT6_MODE='managed'
    
  3. 续订 IPv6 地址:Renew the IPv6 address:

    sudo ifdown eth0 && sudo ifup eth0
    

CoreOSCoreOS

Azure 中最新的 CoreOS 映像已预先配置 DHCPv6。Recent CoreOS images in Azure have been pre-configured with DHCPv6. 使用这些映像不需要进行额外的更改。No additional changes are required when you use these images. 如果 VM 基于旧版或自定义的 CoreOS 映像,请执行以下步骤:If you have a VM based on an older or custom CoreOS image, do the following:

  1. 编辑 /etc/systemd/network/10_dhcp.network 文件 :Edit the /etc/systemd/network/10_dhcp.network file:

     [Match]
     eth0
    
     [Network]
     DHCP=ipv6
    
  2. 续订 IPv6 地址:Renew the IPv6 address:

    sudo systemctl restart systemd-networkd