Baama
Baama

Reputation: 2642

Specify destination server instance in request Azure Load Balancer

Hi I have an server which hosts an azure load balancer. There are multiple server instances the balancer manages. How do i get the sever instance id's from the host ip for the load balancer. Is there a default request to use to get this information. Are there some default headers i must set when sending a request. I primarily want to inform the load balancer to send my request to specific server instances.

I only have the public ip of the load balancer and i need to get all the server instances and send my http request to specific server instances. Can i do all this with with only the ip address? I am new with this

Upvotes: 0

Views: 352

Answers (1)

Jason Ye
Jason Ye

Reputation: 13974

Load balancer with multiple server instances, do you mean your create multiple Azure VMs and a Load balancer in Azure ARM module? If yes, we can use PowerShell to get the information about VMs, like this:

Login-AzureRmAccount
Get-AzureRmPublicIpAddress | ?{ $_.ipaddress -eq "52.168.145.1" } | select name, resourcegroupname
$pip = Get-AzureRmPublicIpAddress -Name mypublicip -ResourceGroupName lb
$lbname = ($pip.IpConfiguration.Id -split '/')[8]
$lbinfo = Get-AzureRmLoadBalancer -Name $lbname -ResourceGroupName lb
$backendips = $lbinfo.BackendAddressPools.BackendIpConfigurations.id
$nics = foreach($id in $backendips){($id -split '/')[8]}
$vms = foreach($nic in $nics){$test = Get-AzureRmNetworkInterface -Name $nic -ResourceGroupName lb ; $vmname =($test.VirtualMachine.id -split '/')[-1];$vmaddress=$test.IpConfigurations.PrivateIpAddress;$results = [pscustomobject]@{'VMname'=$vmname;'PrivateAddress'=$vmaddress};$results }
$vms

Here is the test in my lab:

enter image description here

Upvotes: 0

Related Questions