如何在Azure量表集中获取虚拟机的公共DNS名称

发布于 2025-02-10 09:43:57 字数 868 浏览 4 评论 0原文

我使用Azure Portal的链接创建了使用VM量表集

az vmss create -n XXX -g XXX --image XXX --public-ip-per-vm --vm-domain-name myvmss --vm-sku Standard_B1s --instance-count 1 --admin-password XXX --admin-username XXX--authentication-type password

,然后可以使用SSH进入该VM。

现在,我需要配置它,为此,我需要知道将哪些公共DNS记录分配给VM。我该怎么做?

我计划使用“用于Linux的自定义脚本”扩展程序运行VM的配置。

主机名返回VM的计算机名称(例如MKVMSA524000001),我需要拥有公共IP的完整DNS名称,例如vm1.myvmss.westeurope。 cloudapp.azure.com(myVMSS从上面的命令中有vm-domain-name arg)。

如果有帮助 - 我正在使用基于Linux的图像。

我可以使用实例的公共IP地址,

curl -H Metadata:true --noproxy "*" "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-08-01&format=text"

但是如何获得其名称,例如vm-01?然后我可以手动添加后缀

I created VM Scale Set using

az vmss create -n XXX -g XXX --image XXX --public-ip-per-vm --vm-domain-name myvmss --vm-sku Standard_B1s --instance-count 1 --admin-password XXX --admin-username XXX--authentication-type password

And then I am able to ssh into that VM using a link from azure portal.

Now I need to configure it and for that I need to know what public DNS record was assigned to VM. How can I do it?

I plan to run the configuration of the VMs using "Custom Script For Linux" extension.

hostname returns the computer name of the VM (e.g. mkvmsa524000001) and I need to have the full DNS name of the public IP, e.g. vm1.myvmss.westeurope.cloudapp.azure.com (myvmss there is the vm-domain-name arg from the command above).

If it helps - I am using Linux based image.

I can get the public IP address of the instance using

curl -H Metadata:true --noproxy "*" "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-08-01&format=text"

But how to get its name, e.g. vm-01? I could add the suffix manually then

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自控 2025-02-17 09:43:57

根据这篇文章找到了一个选项 - https://msftstack.wordpress.com/2017/05/05/10/figuring-ob-azure-vm-scale-scale-scale-set-machine-names/

来自VM的主机名,有可能获得比例集中的索引:

def hostname_to_vmid(hostname):
    # get last 6 characters and remove leading zeroes
    hexatrig = hostname[-6:].lstrip('0')
    multiplier = 1
    vmid = 0
    # reverse string and process each char
    for x in hexatrig[::-1]:
        if x.isdigit():
            vmid += int(x) * multiplier
        else:
            # convert letter to corresponding integer
            vmid += (ord(x) - 55) * multiplier
        multiplier *= 36
    return vmid

可以使用$(主机名)找到主机名,然后将DNS名称构建为

vm{index}.{vm-domain-name}.{region}.cloudapp.azure.com

Found an option based on this post - https://msftstack.wordpress.com/2017/05/10/figuring-out-azure-vm-scale-set-machine-names/

From the hostname of the VM it is possible to get the index of it in the Scale Set:

def hostname_to_vmid(hostname):
    # get last 6 characters and remove leading zeroes
    hexatrig = hostname[-6:].lstrip('0')
    multiplier = 1
    vmid = 0
    # reverse string and process each char
    for x in hexatrig[::-1]:
        if x.isdigit():
            vmid += int(x) * multiplier
        else:
            # convert letter to corresponding integer
            vmid += (ord(x) - 55) * multiplier
        multiplier *= 36
    return vmid

Host name can be found using $(hostname) and then build DNS name as

vm{index}.{vm-domain-name}.{region}.cloudapp.azure.com
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文