Skip to content

Commit 0eca239

Browse files
authored
Merge pull request #232713 from mohitp930/mp3292023-freshness-pass-2036655
Freshness Pass User Story: 2036655(https://mseng.visualstudio.com/Tec…
2 parents e6485ed + 952af37 commit 0eca239

File tree

3 files changed

+53
-25
lines changed

3 files changed

+53
-25
lines changed
80.3 KB
Loading
138 KB
Loading
Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,82 @@
11
---
2-
title: Viewing and Modifying Hostnames
3-
description: How to view and change hostnames for Azure virtual machines, web and worker roles for name resolution
2+
title: View and Modify hostnames
3+
description: Learn how to view and modify hostnames for your Azure virtual machines by using the Azure portal or a remote connection.
44
services: virtual-network
55
author: asudbring
66
manager: dcscontentpm
77
ms.assetid: c668cd8e-4e43-4d05-acc3-db64fa78d828
88
ms.service: virtual-network
99
ms.topic: how-to
1010
ms.workload: infrastructure-services
11-
ms.date: 05/14/2021
11+
ms.date: 03/29/2023
1212
ms.author: allensu
1313
---
1414

15-
# Viewing and modifying hostnames
16-
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. You do that by adding the desired host name to the **vmName** attribute of the **Role** element. The value of the **vmName** attribute is used as a base for the host name of each role instance. For 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. For more information about configuring a Microsoft Azure service, see [Azure Service Configuration Schema (.cscfg File)](/previous-versions/azure/reference/ee758710(v=azure.100))
15+
# View and modify hostnames
1716

18-
## Viewing hostnames
19-
You can view the host names of virtual machines and role instances in a cloud service by using any of the tools below.
17+
The hostname identifies your virtual machine (VM) in the user interface and Azure operations. You first assign the hostname of a VM in the **Virtual machine name** field during the creation process in the Azure portal. After you create a VM, you can view and modify the hostname either through a remote connection or in the Azure portal.
2018

21-
### Service configuration file
22-
You can download the service configuration file for a deployed service from the **Configure** blade of the service in the Azure portal. 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. For 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*.
19+
## View hostnames
20+
You can view the hostname of your VM in a cloud service by using any of the following tools.
21+
22+
### Azure portal
23+
24+
In the Azure portal, go to your VM, and select **Properties** from the left navigation. On the **Properties** page, you can view the hostname under **Computer Name**.
25+
26+
:::image type="content" source="./media/virtual-networks-viewing-and-modifying-hostnames/virtual-machine-properties.png" alt-text="Screenshot that shows the Properties page of a virtual machine and highlights the Computer Name.":::
2327

2428
### Remote Desktop
25-
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:
29+
You can connect to your VM using a remote desktop tool like Remote Desktop (Windows), Windows PowerShell remoting (Windows), SSH (Linux and Windows) or Bastion (Azure portal). You can then view the hostname in a few ways:
2630

27-
* Type hostname at the command prompt or SSH terminal.
28-
* Type ipconfig /all at the command prompt (Windows only).
31+
* Type *hostname* in PowerShell, the command prompt, or SSH terminal.
32+
* Type *ipconfig /all* in the command prompt (Windows only).
2933
* View the computer name in the system settings (Windows only).
3034

31-
### Azure Service Management REST API
35+
### Azure API
3236
From a REST client, follow these instructions:
3337

34-
1. 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](/previous-versions/dynamicsnav-2013/dn385850(v=nav.70)).
35-
2. Set a header entry named x-ms-version with a value of 2013-11-01.
36-
3. Send a request in the following format: `https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>?embed-detail=true`
37-
4. Look for the **HostName** element for each **RoleInstance** element.
38+
1. Ensure that you have an authenticated connection to the Azure portal. Follow the steps presented in [Create an Azure Active Directory application and service principal that can access resources](/azure/active-directory/develop/howto-create-service-principal-portal).
39+
2. Send a request in the following format:
40+
41+
```http
42+
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2022-11-01`.
43+
```
44+
45+
For more information on GET requests for virtual machines, see [Virtual Machines - Get](/rest/api/compute/virtual-machines/get).
46+
3. Look for the **osProfile** and then the **computerName** element to find the host name.
3847
3948
> [!WARNING]
40-
> 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).
49+
> You can also view the internal domain suffix for your cloud service 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).
4150
>
4251
>
4352
44-
## Modifying a hostname
45-
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.
53+
## Modify a hostname
54+
You can modify the hostname for any VM by renaming the computer from a remote desktop session or by using **Run command** in the Azure portal.
4655
47-
## Next steps
48-
[Name Resolution (DNS)](virtual-networks-name-resolution-for-vms-and-role-instances.md)
56+
From a remote session:
57+
* For Windows, you can change the hostname from PowerShell by using the [Rename-Computer](/powershell/module/microsoft.powershell.management/rename-computer) command.
58+
* For Linux, you can change the hostname by using `hostnamectl`.
59+
60+
You can also use run these commands to find the hostname for your VM from the Azure portal by using **Run command**. In the Azure portal, go to your VM, and select **Run command** from the left navigation. From the **Run command** page in the Azure portal:
61+
* For Windows, select **RunPowerShellScript** and use `Rename-Computer` in the **Run Command Script** pane.
62+
* For Linux, select **RunShellScript** and use `hostnamectl` in the **Run Command Script** pane.
4963
50-
[Azure Service Configuration Schema (.cscfg)](/previous-versions/azure/reference/ee758710(v=azure.100))
64+
The following image shows the **Run command** page in the Azure portal for a Windows VM.
5165
52-
[Azure Virtual Network Configuration Schema](/previous-versions/azure/reference/jj157100(v=azure.100))
66+
:::image type="content" source="./media/virtual-networks-viewing-and-modifying-hostnames/virtual-machine-run-command.png" alt-text="Screenshot that shows the Run command page for a Windows virtual machine and highlights the RunPowerShellScript feature.":::
5367
54-
[Specify DNS settings using network configuration files](/previous-versions/azure/virtual-network/virtual-networks-specifying-a-dns-settings-in-a-virtual-network-configuration-file)
68+
After you run either `Rename-Computer` or `hostnamectl` on your VM, you need to restart your VM for the hostname to change.
69+
70+
## Azure classic deployment model
71+
72+
The Azure classic deployment model uses a configuration file that you can download and upload to change the host name. To allow your host name to reference your role instances, you must set the value for the host name in the service configuration file for each role. You do that by adding the desired host name to the **vmName** attribute of the **Role** element. The value of the **vmName** attribute is used as a base for the host name of each role instance.
73+
74+
For example, if **vmName** is *webrole* and there are three instances of that role, the host names of the instances are *webrole0*, *webrole1*, and *webrole2*. You don't need to specify a host name for virtual machines in the configuration file, because the host name for a VM is populated based on the virtual machine name. For more information about configuring a Microsoft Azure service, see [Azure Service Configuration Schema (.cscfg File)](/previous-versions/azure/reference/ee758710(v=azure.100))
75+
76+
### Service configuration file
77+
In the Azure classic deployment model, you can download the service configuration file for a deployed service from the **Configure** pane of the service in the Azure portal. 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. For example, if **vmName** is *webrole* and there are three instances of that role, the host names of the instances are *webrole0*, *webrole1*, and *webrole2*. For more information, see [Azure Virtual Network Configuration Schema](/previous-versions/azure/reference/jj157100(v=azure.100))
78+
79+
80+
## Next steps
81+
* [Name Resolution (DNS)](virtual-networks-name-resolution-for-vms-and-role-instances.md)
82+
* [Specify DNS settings using network configuration files](/previous-versions/azure/virtual-network/virtual-networks-specifying-a-dns-settings-in-a-virtual-network-configuration-file)

0 commit comments

Comments
 (0)