REST URI to get the ip address of a VM in azure - azure

I need the rest URL to get the public ip address of a VM created in azure.
I am to list all the public URL's in my subscription from :
https://msdn.microsoft.com/en-us/library/azure/mt163635.aspx
I am also able to get all VM details.
https://learn.microsoft.com/en-us/rest/api/compute/virtualmachines?redirectedfrom=MSDN
But am not able to get the the associated ip for a particular VM!!
Any idea??
Thanks in advance

According to the link you mentioned above, it seems that you are using the Azure Resource Manager (ARM) VM.
But am not able to get the the associated ip for a particular VM!!
Different with Azure Service Management (ASM), the ARM VM doesn't bind the IP Address to the VM directly. In ARM, the VM is associated with NICs and each NIC can be associated with a public IP address.
So, in ARM mode, you need to find the NICs in the details of VM and then get the IP address associated with these NICs.
To get the detailed information of a specific public IP address, please use the following REST URL:
https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resoucegroup-name}/providers/Microsoft.Network/publicIPAddresses/{publicipaddress-name}?api-version={api-version}

Related

Azure Container Instance not using public IP

Tldr:
The issue is that the IP address the agent uses doesn't match the public IP address attached to the container Instance. It's like it is using some hidden internal IP address that isn't visible to an end user.
Background:
I setup a self-hosted DevOps agent in an Azure Container Instance. I added a public IP so I could whitelist it in my subscription, and the DevOps agent would have access to alter resource per Terraform templates.
Problem:
The agent is unable to alter resources that have firewall rules, despite adding the container Instance IP to the whitelist. The error message states failure due to network access from an unapproved IP address. The issue is that the IP address the agent uses doesn't match the public IP address attached to the container Instance. It's like it is using some hidden internal IP address that isn't visible to an end user.
Anyone encountered this before? The whole reason I decided on a self-hosted agent was to avoid the IP hopping problem caused by using DevOps hosted agents.
I just tried with a simple curl container, outgoing IP is different with the IP the container is exposed on. This is something I'd expect to see as well (I believe it would be using Kubernetes underneath). Nothing you can do about that.
You can create a container in the VNet, hence you won't need to whitelist random IP addresses. or you can just create a VM assign a Public IP to it and whitelist that IP (that will always work).

Azure VMSS : Retrieve FQDN

I have created a Virtual machine scale set in Azure and now require to access FQDN of instance from inside of VM. Tried these:
1. Using Azure metadata service. It surprisingly does not have FQDN field.
2. used Hostname -f it gave an fqdn but I think it is to be used internally in azure as it is not accessible from outside.
3. Tried listing public IP of VMSS but how to filter it to show public ip related my VM escapes me.
Update : In AWS "curl http://169.254.169.254/latest/meta-data/public-hostname" commands give the intended output. I am looking for its equivalent
For now, it's not possible to get FQDN from metadata server.
More information about data categories are available through the Instance Metadata Service, please refer to this link.
Does your VMSS instances create with public IP addresses? if yes, you can use Powershell or Azure portal to find the FQDN.

Is it Possible to Convert Azure Classic VM dynamic IP (VIP) to Static IP (VIP)?

I have a Classic Azure VM whose current public ip is dynamic. I want this same ip to convert to Static. Is it possible?
If Yes, How?
I want this same ip to convert to Static. Is it possible?
Yes,you can reserve the IP address to achieve that.
Reserved IPs can be used only as a VIP, ensuring that the IP address for the cloud service remains the same, even as resources are shut down or stopped (deallocated).
To reserve the IP address of a cloud service TestService in the Central US location, run the following PowerShell (Classic) command:
New-AzureReservedIP –ReservedIPName MyReservedIP –Location "Central US" -ServiceName TestService
You can see more details about converting existing dynamic IPs used as a VIP to a reserved IP address in this official document.

Azure Virtual Network / VM's Setup to Share One Public IP

I've recently setup a point to site VPN on Azure. In doing so I have created:
Azure Virtual Network
Azure Virtual Network Gateway
Azure Virtual Network Gateway IP (static)
Azure VM
I was under the impression that any VM set to use the above said Virtual Network would all share the same public IP? However it appears that the Azure VM i setup is instead using its own dynamic public IP.
Is there a way to route any VM on the Custom Virtual Network I created through one public IP? IF so - how can I do this?
According to your description, you have create a point-to-side VPN. in this scenario, we can remove the public IP addresses from VMs, then you can access your VMs with private IP addresses via VPN.
You are correct - I have the VPN working correctly. My only concern is this, it'd be great that if any of those VM's in that private network shared the same static IP - that way I could grant access to that IP in my firewall to other systems i have in other hosting platforms (as they are all typically locked down by ip).
It sounds like your reference to availablity sets may be the phrase i was looking for to further google.. i will check it out and let me know
please let me know if anything I added above changes your answer/recommendations :)
I was under the impression that any VM set to use the above said
Virtual Network would all share the same public IP?
You are talking about Azure ASM module (classic). In ASM module, VMs can use the same public IP address(NAT).
However it appears that the Azure VM i setup is instead using its own
dynamic public IP.
In Azure resource module, we can create Azure VMs with different Public IP addresses.
Is there a way to route any VM on the Custom Virtual Network I created
through one public IP?
According to your description, you have create a point-to-side VPN. in this scenario, we can remove the public IP addresses from VMs, then you can access your VMs with private IP addresses via VPN.
If you want to access those VMs from Internet and use one public IP address, we can create VMs in the same availability set, and deploy a Internet facing load balancer, then add NAT rules to them, in this way, we can access those VMs use the same public IP address and different ports.

Azure Reserved IP Address Inconsistency

I had a need to add additional public IP addresses to an Azure VM and found a working solution here:
Azure VM: More than one Public IP
Essentially this creates a reserved IP in Azure and then adds the reserved IP to a cloud service. Once it's bound to a cloud service it can be mapped to a VM endpoint.
This all works great but there is one bit I don't understand - The IP address of the reserved IP and the resultant VM endpoint don't match. I have to set up DNS to point to the IP address of the endpoint to make this work. Is there something I am not doing right, or is this just the way reserved VMs work?
It looks like this unanswered question is the same issue:
azure reserved IP for VM is diffrent than the given
Thanks!
The "Azure Cloud Service" is a container that provides internet connectivity to "Azure VMs". Thus, you assign the Internet facing Public IP to the Cloud Service. This article is relatively good at explaining the relationship: Azure Cloud Services
From above link:
Here’s a definition of an Azure IaaS cloud service that will make it easy for you to understand what it is in the context of Azure Infrastructure Services:
A cloud service is a network container where you can place virtual machines.
All virtual machines in that container can communicate with each other directly through Azure (and therefore don’t have to go out to the Internet to communicate with each other).
This container is also assigned a DNS name that is reachable from the Internet.
A rudimentary DNS server is created and can provide name resolution for all virtual machines within the same cloud service container (note that name resolution provided by the DNS server is only available to the virtual machines that are located within the cloud service).
One or more Virtual IP Addresses (VIPs) are assigned to the container and these IP addresses can be used to allow inbound connections from the Internet to the virtual machines.
Certain services (like FTP) may require your vm have a public IP: Azure VM Public IP
(IaaS v1) An Azure cloud service comes with a permanent DNS name - something.cloudapp.net - and has a single VIP allocated whenever there are VMs deployed in it OR whenever a reserved IP address is associated with it. Traffic is either load balanced or NATted (port forwarded) to the VM from the Azure Load Balancer sitting on the VIP. You can also associate a public instance-level IP address (PIP) with a VM, which gives it an additional IP address. The VIP always has a DNS name (something.cloudapp.net) while the PIP has one only if you specifically add it, I did a post which goes into these differences.
(IaaS v2) VMs are not deployed into cloud services and only have a public IP address if one is specifically added - either by configuring a PIP on the NIC of the VM (and optionally giving it a cloudapp.azure.com DNS name) or by configuring a load balancer and either load balancing or NATting traffic to it. This load balancer is configured with a public IP address and can optionally have a cloudapp.azure.com DNS name associated with it. (Ignoring internal load balancers in this discussion.)

Resources