How do I get a public IP for my Azure VM? - powershell

I have deployed a VisualStudio web app onto my Azure VM and I need a public IP to the VM so that the public can use my URL to access the web.
The Azure Doc. says: "Every Virtual Machine is automatically assigned a free public Virtual IP (VIP) address. "
..but I can't find how to get this IP.
I tried "VM > Powershell > ipconfig > IPv4 Address. . . . . ."
but I cannot ping this IP from the Internet.

"Every Virtual Machine is automatically assigned a free public Virtual IP (VIP) address"
In order to find out the public ip goto-
Azure portal and then your VM dashboard. Here at the right side you see a quick glance tab under which you will be able to see the public IP. Snapshot for your reference-
Using powershell you can use below command for the same.
Get-AzureVM -ServiceName "testservice" -Name "testvm" | select PublicIPAddress
NOTE - Public IP will be null if instance is in stopped state. To know more on public IP you can read this-
https://azure.microsoft.com/en-in/documentation/articles/virtual-networks-instance-level-public-ip/

ICMP (ping) is not permited to bypass Azure gateways, Try check connectivity with other TCP tools (ie. TELNET / SSH / RDP etc ).
To get the IP address of the VM - you can simply go to www.whatismyip.com

Related

How to enable inbound port in Hyper-V inside Azure VM?

Problem Description
We used to set up an Ubuntu Azure VM (consider Private IP as 109.11.23.11) for sending some simulated data. We need to set up multiple azure VM's for each one for every simulator.
For that simulator to send data outside we specify an inbound rule for the specific port as below
Here for data receiver we specify the connection details as below
:
Ex: 109.11.23.11:50000
Instead of doing that I want to try out having one Azure Windows Server VM which contains multiple Ubuntu Hyper-V machines
Then I set up that Windows server machine and then enabled Hyper-V. And then setup a virtual network to be used by Hyper V using the below Powershell script
New-VMSwitch -Name VmNAT -SwitchType Internal
New-NetNat -Name LocalNAT -InternalIPInterfaceAddressPrefix "192.168.49.0/24"
Get-NetAdapter "vEthernet (VmNat)" | New-NetIPAddress -IPAddress 192.168.49.1 -AddressFamily IPv4 -PrefixLength 24
Install-WindowsFeature -Name 'DHCP' –IncludeManagementTools
Add-DhcpServerV4Scope -Name "DHCP Scope" -StartRange 192.168.49.50 -EndRange 192.168.49.250 -SubnetMask 255.255.255.0
Set-DhcpServerV4OptionValue -DnsServer 168.63.129.16 -Router 192.168.49.1
Now I am a bit confused about how to open up port 50000 as in the earlier method for this Hyper-V.
What I tried
I created an inbound rule in the host VM as we have done in the Ubuntu VM earlier. And in the receiver tried giving the public IP of the host machine/Ubuntu Hyper V separately. Both of these things failed. The receiver is not getting connected to this simulator VM as earlier. I did not try with the host machine's private IP yet. Any suggestions?
• Since, you have created a ‘NAT’ subnet and attached an additional NIC (Network Interface Card) to the Azure VM in this subnet which communicates and manages the IP addresses for the nested VMs on the Azure VM, and a regular LAN (Local Area Network) subnet on which the host Azure VM is placed, please ensure that an inbound rule exists for Port 50000 in the NSG (Network Security Group) for the ‘NAT’ subnet NIC. Also, ensure that the network architecture of the nested VMs hosted on Azure VM is as below: -
• Then, also ensure that a virtual switch is created on the Azure VM to forward traffic from the nested VMs via host Azure VM to the internet and vice versa. Execute the below powershell command to add NAT static mapping with the external IP address used by the Azure VM: -
Add-NetNatStaticMapping -NatName "NestedSwitch" -Protocol TCP -ExternalIPAddress 0.0.0.0 -InternalIPAddress 10.4.2.2 -InternalPort 5000 -ExternalPort 5000
Also, create an inbound firewall rule on the Azure host VM by executing the below powershell command for internal switch created on Hyper-V: -
New-NetFirewallRule -RemoteAddress 192.168.217.0/24 -DisplayName "Allow217net" -Profile Any -Action Allow
Also, ensure that port forwarding is enabled for inbound access to happen from the RDP port to the nested VMs on the nested VMs subnet. So, execute the below command on the host Azure VM to forward the traffic to the concerned ports: -
Add-NetNatStaticMapping -ExternalIPAddress "0.0.0.0/24" -ExternalPort 50004 -Protocol TCP -InternalIPAddress "192.168.0.4" -InternalPort 3389 -NatName NATNetwork
Also, ensure that the below command is executed on the Azure VM to map the listening port to the required NIC on the nested VMs: -
netsh interface portproxy add v4tov4 listenaddress=<nat address> listenport=<random port> connectaddress=<nested vm address> connectport=<nested vm service port>
The above solutions should help you to resolve your issue for inbound rules on the nested VMs.

Set-AzureRmNetworkInterface : Private static IP address does not belong to the range of subnet prefix

I have recently created a virtual machine in Azure where I have installed WordPress and MySQL in it. I have created a Web App too. Now I need to assign my static Web App IP address to the Virtual machine I created. I tried the following commands but no luck there.
New-AzureReservedIP –ReservedIPName IP –Location "South Central US" -ServiceName ServName
I am using latest Azure Powershell in my virtual machine. When I search for a solution people are saying the commands I used are not compatible with the latest powershell. So I used the commands explained here as follows.
$nic=Get-AzureRmNetworkInterface -Name networkinterfacename -ResourceGroupName resouorcegrpupname $nic.IpConfigurations[0].PrivateIpAllocationMethod = 'Static' $nic.IpConfigurations[0].PrivateIpAddress = 'ip address' Set-AzureRmNetworkInterface -NetworkInterface $nic
But when I run I am getting error as
Set-AzureRmNetworkInterface : Private static IP address does not belong to the range of subnet prefix 10.0.0.0/24.
Any help is much appreciated. Thanks in advance.
Note : I have logged in to the Powershell and I am able to run the commands Add-AzureAccount, Select-AzureSubscription, Get-AzureStorageAccount.
Private static IP address does not belong to the range of subnet prefix 10.0.0.0/24.
This error message has clearly described the root cause of this issue. I suppose that the static IP address doesn't reside in the subnet 10.0.0.0/24.
You have two options to overcome this issue:
Change the static IP address. (Choose an available IP from the subnet 10.0.0.0/24)
Create a new subnet which contains your static IP address.
Note: All the subnets must belong to same VNET. Azure doesn't support move the VM to another VNET.
Here is a good article about how to move the VMs between the subnets.

Azure Power Shell - How to change network subnet

I'm trying to change an existing VM deployed via Resource Manager in Azure. The VM is configured with a wrong VirtualNetwork / Subnet. Changing this via portal.azure.net is not possible.
I've managed to retrieve the required network adapter by running: $adapter = Get-AzureRmNetworkInterface -Name xxxxx -ResourceGroupName xxxxx.
I can see the current configured subnet id via $adapter.IpConfigurations.Subnet and I've retrieved the new subnet via $net = Get-AzureRmVirtualNetwork -ResourceGroupName xxxxx -Name xxxxx.
I tried changing the $net.IpConfigurations.Subnet.Id = $net.Subnets.Id but I get a failure :
Subnet default referenced by resource xxxx is not the same Virtual
Network ....
Can anybody tell me how to change the virtual network that a network adapter is using if it was deployed using Resource Manager (the "Classic" has the simple Set-Subnet command).
Changing the Virtual Network for an exiting ARM deployed VM is not possible. But, changing the subnet for a VM is quite easy.
Login the Azure Portal
In Resource groups, choose the resource group your VM is in.
Choose your VM in the resources list of your resource group.
in Setting blade of your VM, and choose Network Interfaces.
Select the network interface you want to change, and click IP Address.
Choose a Subnet, and specify an IP address, or choose Dynamic Assignment.
If none of the exiting subnets meets your requirement, click your Virtual network to create a new subnet.
If you really want to change the Virtual Network of your VM, you can backup your OS Disk, and create a new VM with the OS Disk, and of course with the desired Virtual Network.

Trigger task in AzureVM from local machine via command line

What is the way to trigger a task that is in task manager of AzureVM from command prompt of my local machine??
I tried this (with AzureVm and task names)
schtasks /run /s <VMName> /tn <TaskName>
This gave me the error
ERROR: The network path was not found.
Both AzureVM and local machine are running windows server 2012 R2.
To properly answer this question it will depend on what network connectivity exists between your local machine and the Azure VM. If you are connecting to the Azure VM over the internet then you need to either open a port for the VM on the load balancer, or you need to create a public IP address for the specific VM so that you can access all of the ports of the VM over the internet. Alternatively if you have a site to site or point to site connection to the VM then you can access the VM directly as you are doing.
Assuming that you are connecting to the VM over the internet, the easiest approach is going to be to create a public IP address for the VM, then connect to the VM using either the DNS name of the public IP address or just using the IP address directly. If you wanted to go through the load balancer then you would need to determine which port and protocol (UPD/TCP) schtasks is using so that you can open the correct port.
Also remember that the Windows Firewall on the VM may need to be updated to allow scheduled tasks to be executed remotely.
An alternate option is to use Remote PowerShell to execute the schtasks on the VM. Please see the following blog post that provides great overview on using remote powershell with Azure VMs: http://michaelwasham.com/windows-azure-powershell-reference-guide/introduction-remote-powershell-with-windows-azure/

Can I use AWS Tools for Powershell to create a new EC2 instance and set the private IP?

Cmdlet:
New-EC2Instance -ImageId ami-abcdefg123 -MinCount 1 -MaxCount 1 -KeyName Keypair `
-SecurityGroupId sg-abcdefg -InstanceType m1.small `
-SubnetId subnet-01bd1e76
How can I change this to add a private IP address to this instance? Also, I don't want a public IP address assigned to it.
You should always be assigned a private IP address on instance launch. In EC2 classic, this is assigned from the EC2-Classic range every time your instance is started. In a VPC, this address is static (doesn't reset on stop/start) and comes from the address range of your subnet.
You can disable public IP assignment, but be aware of the default settings for assignment of Public IPs:
EC2-Classic: Your instance receives a public IP address. This behavior
cannot be changed.
Default Subnet: Your instance receives a public IP address by default,
unless you specify otherwise during launch, or you modify the subnet's
public IP address attribute.
Nondefault Subnet: Your instance doesn't receive a public IP address
by default, unless you specify otherwise during launch, or you modify
the subnet's public IP address attribute.
Since you've specified a SubnetId in your New-EC2Instance I can safely assume you're working in a VPC, and since you're asking this question I can assume that the VPC is configured to set the public IP address by default.
In this case, toggling the assignment of a public IP address is as simple as specifying the -AssociatePublicIP parameter of New-EC2Instance.
Example 1: Simply toggle off on EC2 Launch
New-EC2Instance -ImageId ami-abcdefg123 -MinCount 1 -MaxCount 1 -KeyName Keypair `
-SecurityGroupId sg-abcdefg -InstanceType m1.small `
-SubnetId subnet-1a2b3c4d -AssociatePublicIP $false
Example 2: Disable default public IP on all new instances in your subnet. Use -Force when specifying this in a script to skip interactive confirmation.
Edit-EC2SubnetAttribute -MapPublicIpOnLaunch $false -SubnetId subnet-1a2b3c4d -Force
Documentation:
AWS Tools for PowerShell - New-EC2Instance
AWS Tools For PowerShell - Edit-EC2SubnetAttribute
AWS User Guide - Assigning a Public IP Address - Describes some default behavior and options for toggling this feature on/off.
AWS User Guide - IP Addressing in your VPC