0

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.

Gerben
  • 363
  • 1
  • 7
  • you probably heard there is this thing called dns and there is this thing called reverse-search – 4c74356b41 Jul 12 '18 at 20:36
  • Yes but i don't want to create a dns-record for this, I just want a simple local hostname mapping in the cloud shell instance. If it is not possible then I will create a CNAME to the public ip-address. To clear things up I don't need reverse lookup simple hostname to ip is enough. – Gerben Jul 12 '18 at 20:39
  • you can reverse search ip as well – 4c74356b41 Jul 12 '18 at 20:41
  • Thanks you did help me a bit, I just assigned a dns to the public IP in azure which is easy, but still I would prefer a short local hostname that resolves to the public IP. – Gerben Jul 12 '18 at 20:48

1 Answers1

2

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.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39