Changing Static IP in Azure VM (Ubuntu OS) - azure

Is it possible to change the static IP provisioned with a classic VM (Ubuntu OS)? If so, could you please provide the steps of how to do so?
I recently deployed CloudFlare with my infrastructure, primarily for DDOS prevention. One of the requirements is changing the server IP so that malicious vectors who know the server IP can't just bypass CloudFlare and DDOS my infrastructure. I'm using a static IP; how do I change that? Thanks in advance.

IP addresses in Azure fall into two categories: dynamic and reserved. Public IP addresses managed by Azure are dynamic by default.
Is it possible to change the static IP provisioned with a classic VM
(Ubuntu OS)?
Yes, we can use PowerShell to set/remove/add reserved VIP for Azure classic VM.
Reserved IP address 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).
New-AzureReservedIP –ReservedIPName MyReservedIP –Location "Central US"
Get-AzureReservedIP
set-AzureReservedIPAssociation -ReservedIPName MyReservedIP -ServiceName TestService
More information about reserved IP address, please refer to this link.

Related

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.

Assign VNet IP address to Azure Cloud Service

I have an Azure Cloud Service, and a Azure Virtual Network with Subnet.
I can deploy the Cloud Service onto the Virtual Network by setting the appropriate configuration setting in the .cscfg.
What I'm struggling with though is bringing the role onto a specific IP address. My guess is that it's currently using DHCP to get an IP address.
I've tried using the following Powershell:
Get-AzureVM -ServiceName myrole | Set-AzureStaticVNetIP -IPAddress 127.16.0.4 | Update-AzureVM
But the IP address never changes:
<IpAddress>172.16.0.5</IpAddress>
Is there a restriction on doing this on cloud services?
Any help would be really appreciated.
Thanks,
Graeme
Network configuration schema for Cloud Service is documented here.
https://msdn.microsoft.com/library/azure/jj156091.aspx
As you'll see, you have the ability to specify a ReservedIP but not a static private IP.
My understanding is that Set-AzureStaticVNetIP works for Azure IaaS VM, not for Cloud Service VM.
Virtual machines whether there are IaaS or Paas provisioned in a VNET are always allocated the first available IP address in the subnet after the first 4 addresses which are reserved from .0 to .3.
So considering your request, I will define subnets that enable to target the right subnet IPs for my role instances, and if I need to precisely know which IP is used by which instance, read it in the "role start" method and use it to configure whatever solution you need for this IP to be be "static".
Hope this helps
Best regards
Stéphane

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.)

Azure VM: Adding a Reserved IP address to an existing VM

What I have read so far on the web is that there is no way to add a reserved IP to an existing VM (unless I recreate the VM which I am trying to avoid). However, I have noticed that external IP of my VM and the cloud service is same.
Reserved IP Addresses page explains how to "To use a Reserved IP with Cloud Services". I have looked everywhere in the Azure Management Portal but couldn't find a configuration setting for Service Configuration Schema.
I am using the Azure scheduler to turn-off the VMs at night and on the weekends. From the following I understand is that there is something that I need to write in the scheduler script to re-assign the Reserved IP when the VM starts in the morning. Did I get it right?
Shutdown VM - Previously, when all the Virtual Machine instances in a
cloud service were moved to the Shutdown state (stop/deallocated), the
public IP would be released and a new public IP would be assigned when
one of the Virtual Machines instances was started. However, with this
release, if the VM uses a Reserved IP, then the Reserved IP can be
used when re-deploying the VMs.
P.S. Is Stack Overflow the best place to ask this sort of questions relating to Azure or shall I use Server Fault in the future? I have seen Azure questions in both websites.
At Build 2015 they announced this is now possible and VERY easy.
Simply open Azure powershell and run this:
New-AzureReservedIP -ReservedIPName "ipname" -Location "West US" -ServiceName "somevm"
If you run this it will reserve an IP named "ipname" and associate it with the already deployed instance "somevm.cloudapp.net"
In order to assign existing reserved IP to an existing VM, you can use the following command:
Set-AzureReservedIPAssociation -ReservedIPName MyReservedIP -ServiceName TestService
Step by step to create Reserved IP and using it on Azure VM. Here you can go
Reserved IP Creation
I have done the Elastic IP Automatic scheduling on AWS.Here is the reference link Elastic IP Automation on AWS script.
Between needs to check about How can I write a script for automating the reserved IP for Azure.If you had done it earlier, Kindly share the script this will be very useful. Thanks.
At this point, we don't support the capability to associate a Reserved IP to an already existing VM.
We are currently working on the capability to reserve the IP of an existing VM.
Ref: http://azure.microsoft.com/blog/2014/05/14/reserved-ip-addresses/
http://www.petri.com/how-to-reserve-public-virtual-ip-addresses-in-microsoft-azure.htm
Girish Prajwal
For new VMs (with resource manager) you should do the following:
Create new static IP address:
$ip = New-AzureRmPublicIpAddress -Name "<ip-name>" -ResourceGroupName <group-name> -Location eastus -AllocationMethod Static
Get information about VM Network Interface:
Get-AzureRmVM -ResourceGroupName <group-name> -Name <vm-name> | Select -ExpandProperty NetworkProfile
Get corresponding network interface and set new ip and update NIC:
$netInt = Get-AzureRmNetworkInterface -ResourceGroupName "group-name" -Name <nic-name>
$netInt.IpConfigurations[0].PublicIpAddress = $ip
Set-AzureRmNetworkInterface -NetworkInterface $netInt
I read all of the previous entries and did not come away with a clear picture of how to proceed with assigning a reserved IP address to my existing Azure classic VM, so I opened a support ticket. I got excellent clear guidance from "Sruthi Saranya K", a support engineer in Azure Networking. Sruthi stated "in classic deployment model it is not possible to have a static public IP assigned to a VM", which I had read elsewhere, but she clarified that you simply assign the IP address to the cloud service and not the VM directly, then the VM will automatically pick up on the change. I outline all of the commands here for your convenience, starting from an Azure PowerShell prompt. The critical command was specified in the top response here, but not all of the steps. Also, that example also includes specifying the service, but it does not appear to be a supported parameter for that command, instead there is a second command to associate the IP with the service.
add-azureaccount (to log in to Azure from PowerShell)
New-AzureReservedIP -ReservedIPName "ipname" -Location "East US"
get-azurereservedip (just to see what the reserved IP address is)
Set-AzureReservedIPAssociation -ReservedIPName "ipname" -ServiceName "your cloud service name"
Also, depending on the use, you may want to look up the IP address on mxtoolbox.com to make sure it is not already blacklisted. My reserved IP was for a web site, but the default # DNS entry for the domain meant our domain was generally going to be associated with that IP address, and previously our mail has been blacklisted because our web server IP address was sullied by some other Azure tenant. If you get a blacklisted address, you can remove it and get a new one, also a suggestion from Sruthi. Here are the commands to remove the reserved IP, and to remove the cloud service association if needed:
remove-azurereservedip
Remove-AzureReservedIPAssociation
My sincere thanks to Sruthi for making it so simple and preventing an unnecessary redeployment of our company's public web server.
Add Public IP to an Existing VM
Log into the portal
Find the Resource Group (RG) where your VM is Located
Confirm your VM has a network interface - if not, create one (it should have one)
Create a Public IP Address (static or dynamic, doesn't matter) by adding one to your RG from the marketplace (do this first so it is creating while you make your NSG).
Create a Network Service Group by adding one to your RG from the marketplace and associating it with your VM.
Once the NSG has deployed, go back to the Overview of your PIP and click the "Associate" button in the info section of the blade.
Select the Network Interface of your VM you validated in step 3.
Get a cup of coffee or something, it will be a minute, but otherwise you're done.
New-AzureReservedIP -ReservedIPName "nameIP" -Location "East US" -ServiceName "azureA2vm"
Get this:
New-AzureReservedIP : A parameter cannot be found that matches parameter name 'ServiceName'.
At line:1 char:70
+ New-AzureReservedIP -ReservedIPName "nameIP" -Location "East US" -ServiceNam ...
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-AzureReservedIP], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.NewAzureReservedIPCmdlet
Check PowerShell version. Update to latest version.

Azure VM: More than one Public IP

Can anyone confirm if Azure VM allows more than one Public IP? We want to host multiple website on single VM and hence want to have different IP for each website. I know we can host more VM, but that will greatly increase our expense too. So, I just want more than 1 Public IP on VM.
You can add multiple IP addresses for a cloud service. Since the VM's are "inside" the cloud service, this gives you in a way multiple public IP addresses for a virtual machine. The procedure is documented at [1]. Additional addresses currently cost about $3/month.
Here's the steps to add a new reserved IP address to a cloud service.
First create a new reserved IP address:
New-AzureReservedIP –ReservedIPName "MyIPAddress" –Location "West Europe"
Associate the IP address with cloud service:
Add-AzureVirtualIP -VirtualIPName MyIPAddress -ServiceName MyCloudService
Create endpoint that maps the IP address to a virtual machines. If you have multiple vm's and want load balancer, repeat this for each vm. In order to run multiple web sites, you would put each website to different port (the localport). The endpoint listens for connections on the public port and forwards them to the virtual machine's localport.
Get-AzureVM -ServiceName MyCloudService -Name myserver `
| Add-AzureEndpoint -Name QuvastoMail -Protocol tcp `
-LocalPort 8002 -PublicPort 80 -VirtualIPName MyIPAddress `
| Update-AzureVM
[1] http://azure.microsoft.com/en-us/documentation/articles/load-balancer-multivip/
It appears you can now have multiple public IPs for a load balanced cloud service:
http://azure.microsoft.com/en-gb/updates/multiple-vips-per-cloud-service/
Now you can assign more than one load-balanced public IP address to a
set of virtual machines, enabling high-availability and high-scale
scenarios. You can host multiple secure websites in a cloud service or
allow multiple SQL Server AlwaysOn Availability Group listeners to
access the same set of virtual machines.
For more information, please vistit the Load Balancer page. There is
no additional charge for this feature.
You would need a different Cloud Service (either Web Role or Virtual Machine) to have different IP addresses. Yes, this will increase overall cost.
The VIP (public IP) for Windows Azure Web Roles and VMs is assigned at the Cloud Service level. Think of a Cloud Service as a logical container - it can contain web/worker roles or VMs (not both currently).
Very possible, very easy actually.
Have your apps listening at your Azure Resource Managed VM, let's say ports 3001, 3002, 3003..
Then create an Load Balancer (just search it).
Create a Public IP Address.
Add it at your Load Balancer's Front-end Pool
Add your VM to your Load Balancer's Back-end Pool
at Inbound NAT rules of your Load Balancer, click "Add"
Select your frontend IP, your VM's network IP configuration, protocol, port and mapped port (click "Custom") to set a custom port.
Sample:
- You want your newly created public ip "52.165.147.25" to route to your vm's port 3001.
- On config that will be port 80 tcp, then port 3001 on mapped port.
- No need to enable "Floating IP (direct server return)" in case you see it.
PS:
On linux VM's you might have to "Optimize Your Network Kernel Parameters"..
Check here (scroll at bottom): http://docs.fluentd.org/v0.12/articles/before-install
sudo nano /etc/sysctl.conf
Add these entries:
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240 65535
Note the spaces, crucial.
Save it.
sudo sysctl -p
Done.
EDIT:
On the above steps you might have to also take care of CORS (Just google it)
Also, Another alternative I forgot to mention is to add NIC's / Network Interfaces to ya VM's. That won't be a viable option though because of azure max-nic-per-vm limits.
In addition to the earlier answer about Cloud Services, it is now possible to have multiple IP addresses on an Azure VM. https://learn.microsoft.com/en-us/azure/virtual-network/virtual-network-multiple-ip-addresses-portal
You can only have one public IP address per deployment. So if you had 3 VMs in a single deployment, they'd share IP address. You can then choose to load-balance traffic across the instances or direct traffic to a particular VM (or role in cloud services) for a specific port number.
You can use host headers and support multiple websites in a single VM.
We are also having similar problems. We wanted to have multiple SSL certificates applied to multiple sites hosted withing Virtual Machine.
but it seems its not possible at all. Waiting for MS to release this feature.
Comparatively Godaddy and other hosting providers give free 2-3 IP addressed as well if you need more you can request additional Ip Address easily.
as well to get hold of support is too much difficult.
MZ azure really sucks. :(

Resources