Skip to content

Commit 1305874

Browse files
authored
Merge pull request #232675 from divargas-msft/patch-1
[Doc-a-thon] Updating cloudinit-update-vm-hostname
2 parents 6e5ee06 + 4f7ab43 commit 1305874

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

articles/virtual-machines/linux/cloudinit-update-vm-hostname.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@ author: mattmcinnes
55
ms.service: virtual-machines
66
ms.collection: linux
77
ms.topic: how-to
8-
ms.date: 11/29/2017
8+
ms.date: 03/29/2023
99
ms.author: mattmcinnes
1010
ms.subservice: cloud-init
1111

1212
---
1313
# Use cloud-init to set hostname for a Linux VM in Azure
1414

15-
**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
15+
**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets
1616

1717
This article shows you how to use [cloud-init](https://cloudinit.readthedocs.io) to configure a specific hostname on a virtual machine (VM) or virtual machine scale sets (VMSS) at provisioning time in Azure. These cloud-init scripts run on first boot once the resources have been provisioned by Azure. For more information about how cloud-init works natively in Azure and the supported Linux distros, see [cloud-init overview](using-cloud-init.md)
1818

1919
## Set the hostname with cloud-init
20+
2021
By default, the hostname is the same as the VM name when you create a new virtual machine in Azure. To run a cloud-init script to change this default hostname when you create a VM in Azure with [az vm create](/cli/azure/vm), specify the cloud-init file with the `--custom-data` switch.
2122

22-
To see upgrade process in action, create a file in your current shell named *cloud_init_hostname.txt* and paste the following configuration. For this example, create the file in the Cloud Shell not on your local machine. You can use any editor you wish. Enter `sensible-editor cloud_init_hostname.txt` to create the file and see a list of available editors. Choose #1 to use the **nano** editor. Make sure that the whole cloud-init file is copied correctly, especially the first line.
23+
To see upgrade process in action, create a file in your current shell named *cloud_init_hostname.txt* and paste the following configuration. For this example, create the file in the Cloud Shell not on your local machine. You can use any editor you wish. Make sure that the whole cloud-init file is copied correctly, especially the first line.
2324

2425
```yaml
2526
#cloud-config
@@ -28,42 +29,46 @@ fqdn: myhostname
2829
2930
Before deploying this image, you need to create a resource group with the [az group create](/cli/azure/group) command. An Azure resource group is a logical container into which Azure resources are deployed and managed. The following example creates a resource group named *myResourceGroup* in the *eastus* location.
3031
31-
```azurecli-interactive
32+
```azurecli-interactive
3233
az group create --name myResourceGroup --location eastus
3334
```
3435

3536
Now, create a VM with [az vm create](/cli/azure/vm) and specify the cloud-init file with `--custom-data cloud_init_hostname.txt` as follows:
3637

37-
```azurecli-interactive
38+
```azurecli-interactive
3839
az vm create \
3940
--resource-group myResourceGroup \
40-
--name centos74 \
41-
--image OpenLogic:CentOS:7-CI:latest \
41+
--name vmName \
42+
--image imageCIURN \
4243
--custom-data cloud_init_hostname.txt \
4344
--generate-ssh-keys
4445
```
4546

47+
> [!NOTE]
48+
> Replace **myResourceGroup**, **vmName**, and **imageCIURN** values accordingly. Make sure an image with Cloud-init is chosen.
49+
4650
Once created, the Azure CLI shows information about the VM. Use the `publicIpAddress` to SSH to your VM. Enter your own address as follows:
4751

4852
```bash
49-
ssh <publicIpAddress>
53+
ssh <user>@<publicIpAddress>
5054
```
5155

5256
To see the VM name, use the `hostname` command as follows:
5357

5458
```bash
55-
hostname
59+
sudo hostname
5660
```
5761

5862
The VM should report the hostname as that value set in the cloud-init file, as shown in the following example output:
5963

60-
```bash
64+
```output
6165
myhostname
6266
```
6367

6468
## Next steps
69+
6570
For additional cloud-init examples of configuration changes, see the following:
66-
71+
6772
- [Add an additional Linux user to a VM](cloudinit-add-user.md)
6873
- [Run a package manager to update existing packages on first boot](cloudinit-update-vm.md)
6974
- [Change VM local hostname](cloudinit-update-vm-hostname.md)

0 commit comments

Comments
 (0)