查看和修改主机名Viewing and modifying hostnames

若要允许通过主机名引用角色实例,必须在服务配置文件中为每个角色设置主机名的值。To allow your role instances to be referenced by host name, you must set the value for the host name in the service configuration file for each role. 可以通过将所需主机名添加到 Role 元素的 vmName 属性来执行该操作。You do that by adding the desired host name to the vmName attribute of the Role element. vmName 属性的值用作每个角色实例的主机名的基本元素。The value of the vmName attribute is used as a base for the host name of each role instance. 例如,如果 vmNamewebrole,并且该角色有三个实例,则这些实例的主机名将为 webrole0webrole1webrole2For example, if vmName is webrole and there are three instances of that role, the host names of the instances will be webrole0, webrole1, and webrole2. 无需在配置文件中为虚拟机指定主机名,因为虚拟机的主机名会基于虚拟机名称填充。You do not need to specify a host name for virtual machines in the configuration file, because the host name for a virtual machine is populated based on the virtual machine name. 有关配置 Microsoft Azure 服务的详细信息,请参阅 Azure Service 配置架构(.cscfg 文件)For more information about configuring a Azure service, see Azure Service Configuration Schema (.cscfg File)

查看主机名Viewing hostnames

可以使用下列任一工具来查看云服务中虚拟机和角色实例的主机名。You can view the host names of virtual machines and role instances in a cloud service by using any of the tools below.

服务配置文件Service configuration file

可以从 Azure 门户中服务的“配置”边栏选项卡下载已部署服务的服务配置文件。****You can download the service configuration file for a deployed service from the Configure blade of the service in the Azure portal. 然后,可以查找角色名称元素的 vmName 属性以查看主机名。You can then look for the vmName attribute for the Role name element to see the host name. 请记住,此主机名用作每个角色实例的主机名的基本元素。Keep in mind that this host name is used as a base for the host name of each role instance. 例如,如果 vmNamewebrole,并且该角色有三个实例,则这些实例的主机名将为 webrole0webrole1webrole2For example, if vmName is webrole and there are three instances of that role, the host names of the instances will be webrole0, webrole1, and webrole2.

远程桌面Remote Desktop

启用与你的虚拟机或角色实例的远程桌面 (Windows) 连接、Windows PowerShell 远程处理 (Windows) 连接或 SSH(Linux 和 Windows)连接后,你可以通过多种方式从活动的远程桌面连接查看主机名:After you enable Remote Desktop (Windows), Windows PowerShell remoting (Windows), or SSH (Linux and Windows) connections to your virtual machines or role instances, you can view the host name from an active Remote Desktop connection in various ways:

  • 在命令提示符下或 SSH 终端键入主机名。Type hostname at the command prompt or SSH terminal.
  • 在命令提示符下键入 ipconfig /all(仅限 Windows)。Type ipconfig /all at the command prompt (Windows only).
  • 查看系统设置中的计算机名称(仅限 Windows)。View the computer name in the system settings (Windows only).

Azure 服务管理 REST APIAzure Service Management REST API

从 REST 客户端,按照以下说明进行操作:From a REST client, follow these instructions:

  1. 确保有用于连接到 Azure 门户的客户端证书。Ensure that you have a client certificate to connect to the Azure portal. 若要获取客户端证书,请执行如何:下载和导入发布设置和订阅信息中提供的步骤。To obtain a client certificate, follow the steps presented in How to: Download and Import Publish Settings and Subscription Information.
  2. 使用值 2013-11-01 设置名为 x-ms-version 的标头条目。Set a header entry named x-ms-version with a value of 2013-11-01.
  3. 使用以下格式发送请求:https://management.core.chinacloudapi.cn/<subscrition-id>/services/hostedservices/<service-name>?embed-detail=trueSend a request in the following format: https://management.core.chinacloudapi.cn/<subscrition-id>/services/hostedservices/<service-name>?embed-detail=true
  4. HostName 元素中查找每个 RoleInstance 元素。Look for the HostName element for each RoleInstance element.

Warning

还可以通过以下方式从 REST 调用响应查看云服务的内部域后缀:查看 InternalDnsSuffix 元素,或通过在远程桌面会话 (Windows) 中的命令提示符下运行 ipconfig /all 或通过从 SSH 终端 (Linux) 运行 cat /etc/resolv.conf。You can also view the internal domain suffix for your cloud service from the REST call response by checking the InternalDnsSuffix element, or by running ipconfig /all from a command prompt in a Remote Desktop session (Windows), or by running cat /etc/resolv.conf from an SSH terminal (Linux).

修改主机名Modifying a hostname

可以通过上传已修改的服务配置文件,或从远程桌面会话重命名计算机来修改任何虚拟机或角色实例的主机名。You can modify the host name for any virtual machine or role instance by uploading a modified service configuration file, or by renaming the computer from a Remote Desktop session.

后续步骤Next steps

名称解析 (DNS)Name Resolution (DNS)

Azure 服务配置架构 (.cscfg)Azure Service Configuration Schema (.cscfg)

使用网络配置文件指定 DNS 设置Specify DNS settings using network configuration files