Search code examples
azureazure-cloud-shell

Add local hostname to azure cloud shell


I want to map a public IP address of a vm to a hostname. On a regular linux distribution I would add the ip to hostname mapping to /etc/hosts like so.

52.123.12.23 name-to-resolve

The question is how to achieve the same on a azure cloud shell(bash). So that if I want to ssh into a vm I don't need to remember or query the public IP.

A pragmatic solution would be to create a simpel script to ssh into the vm.


Solution

  • It seems you cannot add the IP to hostname mapping to /etc/hosts, as the document says:

    Permissions are set as regular users without sudo access. Any installation outside your $Home directory is not persisted.

    And the /etc/hosts owner is root, you do not have the permission to edit it. enter image description here

    So, if you want to ssh the Azure VM without IP, you just can set a DNS to the VM Public IP.

    There are some limitations to the Cloud Shell, you can get the details via this document.