Azure虚拟机中是否存在与ec2metadata
类似的内容?
我需要提取公共主机名或实例ID之类的数据。在Amazon EC2实例中,我可以这样做:
$ ec2metadata --instance-id
i-3a1dcfa3
$ ec2metadata --public-hostname
ec2-54-91-124-63.compute-1.amazonaws.com
答案 0 :(得分:1)
很久以前这个问题似乎已被问到,所以也许你已经找到了答案。如果没有,那么您是否尝试过Azure实例元数据? (https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-instancemetadataservice-overview)你可以这样做一个http请求:
curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2017-04-02"
响应如下:
{
"compute": {
"location": "westcentralus",
"name": "IMDSSample",
"offer": "UbuntuServer",
"osType": "Linux",
"platformFaultDomain": "0",
"platformUpdateDomain": "0",
"publisher": "Canonical",
"sku": "16.04.0-LTS",
"version": "16.04.201610200",
"vmId": "5d33a910-a7a0-4443-9f01-6a807801b29b",
"vmSize": "Standard_A1"
},
"network": {
"interface": [
{
"ipv4": {
"ipAddress": [
{
"privateIpAddress": "10.1.0.4",
"publicIpAddress": "X.X.X.X"
}
],
"subnet": [
{
"address": "10.1.0.0",
"prefix": "24"
}
]
},
"ipv6": {
"ipAddress": []
},
"macAddress": "000D3AF806EC"
}
]
}
}
希望这有帮助! :)