Reader small image

You're reading from  Azure Networking Cookbook, Second Edition - Second Edition

Product typeBook
Published inDec 2020
PublisherPackt
ISBN-139781800563759
Edition2nd Edition
Tools
Concepts
Right arrow
Author (1)
Mustafa Toroman
Mustafa Toroman
author image
Mustafa Toroman

Mustafa Toroman is a solution architect focused on cloud-native applications and migrating existing systems to the cloud. He is very interested in DevOps processes and cybersecurity, and he is also an Infrastructure as Code enthusiast and DevOps InstituteAmbassador. Mustafa often speaks at international conferences about cloud technologies. He has been an MVP for Microsoft Azure since 2016 and a C# Corner MVP since 2020. Mustafa has also authored several books about Microsoft Azure and cloud computing, all published by Packt.
Read more about Mustafa Toroman

Right arrow

4. Managing IP addresses

In Azure, we can have two types of IP addresses, private and public. Public addresses can be accessed over the internet. Private addresses are from the Azure Virtual Network address space and are used for private communication on private networks. Addresses can be assigned to a resource or can exist as a separate resource.

We will cover the following recipes in this chapter:

  • Creating a new public IP address in the Azure portal
  • Creating a new public IP address with PowerShell
  • Assigning a public IP address
  • Unassigning a public IP address
  • Creating a reservation for a public IP address
  • Removing a reservation for a public IP address
  • Creating a reservation for a private IP address
  • Changing a reservation for a private IP address
  • Removing a reservation for a private IP address
  • Adding multiple addresses to an NIC
  • Creating a public IP prefix

Technical requirements

For this chapter, the following is required:

  • An Azure subscription
  • Azure PowerShell

The code samples can be found at https://github.com/PacktPublishing/Azure-Networking-Cookbook-Second-Edition/tree/master/Chapter04.

Creating a new public IP address in the Azure portal

Public IP addresses can be created as a separate resource or created during the creation of some other resources (a virtual machine (VM), for example). Therefore, a public IP can exist as part of a resource or as a standalone resource. First, we are going to show you how to create a new public IP address.

Getting ready

Before you start, open your browser and go to the Azure portal at https://portal.azure.com.

How to do it...

To create a new public IP address, we must follow these steps:

  1. In the Azure portal, select Create a resource and choose Public IP address under Networking services (or search for public IP address in the search bar).
  2. The parameters we need to define for deployment are IP Version, SKU, Name, IP address assignment, DNS name label, Subscription, Resource group, and Location. Idle timeout (the amount of time that the connection will stay open with no activity) is defaulted to 4 minutes but...

Creating a new public IP address with PowerShell

Alternatively, we can create a public IP address using Azure PowerShell. Again, this approach is best when we want to automate the process. Even though a public IP address can exist on its own, it's usually created to be associated with other resources and to be used as an endpoint. When using PowerShell to create a resource, we can continue to the next step and join it with a resource in a single script.

Getting ready

Open the PowerShell console and make sure you are connected to your Azure subscription.

How to do it...

To deploy a new public IP address, execute the following command:

New-AzPublicIpAddress -Name 'ip-public-script' -ResourceGroupName 'Packt-Networking-Script' -AllocationMethod Dynamic -Location 'westeurope' 

How it works...

As an outcome, a new public IP address will be created. The settings, in this case, will be a basic SKU dynamic assignment, IPv4 version, and...

Assigning a public IP address

A public IP address can be created as a separate resource or disassociated from another resource and exist on its own. Such an IP address can then be assigned to a new resource or another already-existing resource. If the resource is no longer in use or has been migrated, we can still use the same public IP address. In this case, the public endpoint that's used to access a service may stay unchanged. This can be useful when a publicly available application or service is migrated or upgraded, as we can keep using the same endpoint and users don't need to be aware of any change.

Getting ready

Before you start, open your browser and go to the Azure portal at https://portal.azure.com.

How to do it...

To assign a public IP address, we must do the following:

  1. Locate the network interface (NIC) that you want the IP address to be assigned to. This can be done directly by finding the NIC, or through the VM pane that the NIC is assigned...

Unassigning a public IP address

A public IP address can be unassigned from a resource in order to be saved for later use or assigned to another resource. When a resource is deleted or decommissioned, we can still put the public IP address to use and assign it to the next resource.

Getting ready

Before you start, open your browser and go to the Azure portal at https://portal.azure.com. Make sure that the VM using a public IP address is not running.

How to do it...

To unassign a public IP address, we must do the following:

  1. Locate the NIC that the public IP address is associated with.
  2. In the Network interface pane, go to IP configurations under Settings and select the IP configuration:

    Viewing the IP configurations under the Network interface pane

    Figure 4.4: IP configurations under the NIC pane

  3. In the new pane, change the Public IP address setting to Disassociate:

    Clicking Disassociate under the Public IP address settings to unassign the public IP address

    Figure 4.5: Unassigning the public IP address

  4. After the changes are made, click Save to apply the new configuration.

How it works...

A public...

Creating a reservation for a public IP address

The default option for a public IP address is dynamic IP assignment. This can be changed during the public IP address creation, or later. If this is changed from dynamic IP assignment, then the public IP address becomes reserved (or static).

Getting ready

Before you start, open your browser and go to the Azure portal at https://portal.azure.com.

How to do it...

To create a reservation for a public IP address, follow these steps:

  1. Locate the public IP address in the Azure portal. This can be done by finding the IP address directly, or through the resource it's assigned to (either the NIC or VM).
  2. In the Public IP address pane, go to Configuration under Settings. Change Assignment from Dynamic to Static, as shown in Figure 4.6:

    Setting Assignment to Static in the Public IP address pane to create an IP reservation

    Figure 4.6: Changing the public IP address assignment to Static

  3. After this change has been made, click Save to apply the new settings.

How it works...

A public IP address is...

Removing a reservation for a public IP address

If the public IP address is set to static, we can remove a reservation and set the IP address assignment to dynamic. This isn't done often as there is usually a reason why the reservation is set in the first place. But as the reservation for the public IP address has an additional cost, there is sometimes a need to remove the reservation if it is not necessary.

Getting ready

Before you start, open your browser and go to the Azure portal at https://portal.azure.com. Make sure that the IP address is not associated with any resource.

How to do it...

To remove a reservation for a public IP address, follow these steps:

  1. Locate the public IP address in the Azure portal.
  2. In the Public IP address pane, go to Configuration under Settings and set Assignment to Dynamic:

    Setting Private IP address assignment to Dynamic to remove the IP reservation

    Figure 4.7: Changing the public IP address assignment to Dynamic

  3. After these changes have been made, click Save to apply the new configuration.
  4. ...

Creating a reservation for a private IP address

Similar to public IP addresses, we can make a reservation for private IP addresses. This is usually done to ensure communication between servers on the same virtual network and to allow the usage of IP addresses in connection strings.

Getting ready

Before you start, open your browser and go to the Azure portal at https://portal.azure.com.

How to do it...

To create a reservation for a private IP address, follow these steps:

  1. In the Azure portal, locate the NIC you want to make the reservation for.
  2. In the Network interface pane, go to IP configurations under Settings and select the IP configuration:

    Selecting IP configuration under the Network interface pane

    Figure 4.8: Viewing IP configurations in the NIC pane

  3. In the new pane, under the Private IP address settings, set Assignment to Static. The current IP address value will be set automatically. If needed, you can change that value to another value, but it must be in the address space of the subnet associated with the...

Changing a reservation for a private IP address

For private IP addresses, you can change the IP address at any time to another value. With public IP addresses, this isn't the case, as you get the IP address randomly from a pool and aren't able to change the value. With a private IP address, you can change the value to another IP address from the address space.

Getting ready

Before you start, open your browser and go to the Azure portal at https://portal.azure.com.

How to do it...

To change a reservation for a private IP address, follow these steps:

  1. In the Azure portal, locate the NIC you want to make changes for.
  2. In the Network interface pane, go to IP configurations under Settings and select the IP configuration:

    Clicking IP configuration in the Network interface pane

    Figure 4.10: Locating the IP configuration in the Network interface pane

  3. In Private IP address settings, enter a new value for IP address:

    Entering a new value for Private IP address to change the IP reservation

    Figure 4.11: Assigning a new value for the private IP address

  4. After these changes have been...

Removing a reservation for a private IP address

Similar to public IP addresses, we can remove a reservation for a private IP address at any time. A private IP address is free, so additional costs aren't a factor in this case. But there are scenarios where dynamic assignment is required, and we can set it at any time.

Getting ready

Before you start, open your browser and go to the Azure portal at https://portal.azure.com.

How to do it...

To remove a reservation for a private IP address, follow these steps:

  1. In the Azure portal, locate the NIC you want to make changes for.
  2. In the Network interface pane, go to IP configurations under Settings and select the IP configuration:

    Selecting IP configuration in the Network interface pane

    Figure 4.12: Selecting the IP configuration in the Network interface pane

  3. In the new pane, under Private IP address settings, change Assignment to Dynamic:

    Setting Assignment under the Private IP address settings to Dynamic to remove an IP reservation

    Figure 4.13: Private IP address assignment set to Dynamic

  4. After these changes have been made, click Save to apply the new configuration...

Adding multiple IP addresses to an NIC

In various situations, we may need to have multiple IP addresses associated with a single NIC. In Azure, this is possible for both private and public IP addresses.

Getting ready

Before you start, open your browser and go to the Azure portal at https://portal.azure.com.

How to do it...

  1. In the Azure portal, locate the NIC you want to make changes for.
  2. In the Network interface pane, go to IP configurations under Settings and click Add:
    Clicking the Add button in the IP configuration settings of the Network interface pane

    Figure 4.14: The Network interface pane

  3. A new pane for IP configuration will appear. We need to provide values for the Name and Type fields (Type will be grayed out if another IP configuration already exists), and we need to select some IP address settings. If only a private IP address is needed, we just need to select the private address Allocation and click Create:
    Configuring the Private IP address settings in the new pane

    Figure 4.15: Adding IP configuration to the NIC

  4. If an additional public IP address is needed, we need to select Associate...

Creating a public IP prefix

Creating new resources is usually associated with creating new IP addresses. There can be issues when public IP addresses need to be associated with firewall rules or app configurations. To overcome this, we can create a public IP prefix and reserve a range of IP addresses that will be assigned to our resources.

How to do it...

To create a new public IP prefix, we must follow these steps:

  1. In the Azure portal, select Create a resource and choose Public IP prefix under Networking services (or search for public IP prefix in the search bar).
  2. We need to provide information for Subscription, Resource group, Name, Region, and IP Version. SKU is not selectable and is set to Standard. For Prefix size, we define how many IP addresses we want to reserve:
    Creating a public IP prefix using the Azure portal

Figure 4.17: Creating a public IP prefix

How it works...

When we create a public IP prefix, public IP address association is not done randomly but from a pool of addresses reserved for...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Azure Networking Cookbook, Second Edition - Second Edition
Published in: Dec 2020Publisher: PacktISBN-13: 9781800563759
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Mustafa Toroman

Mustafa Toroman is a solution architect focused on cloud-native applications and migrating existing systems to the cloud. He is very interested in DevOps processes and cybersecurity, and he is also an Infrastructure as Code enthusiast and DevOps InstituteAmbassador. Mustafa often speaks at international conferences about cloud technologies. He has been an MVP for Microsoft Azure since 2016 and a C# Corner MVP since 2020. Mustafa has also authored several books about Microsoft Azure and cloud computing, all published by Packt.
Read more about Mustafa Toroman