|
| 1 | +--- |
| 2 | +title: Deploy a DHCP server in Azure on a virtual machine |
| 3 | +titleSuffix: Azure Virtual Network |
| 4 | +description: Learn about how to deploy a Dynamic Host Configuration Protocol (DHCP) server in Azure on a virtual machine as a target for an on-premises DHCP relay agent. |
| 5 | +author: asudbring |
| 6 | +ms.author: allensu |
| 7 | +ms.service: virtual-network |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 02/28/2024 |
| 10 | + |
| 11 | +#customer intent: As a Network Administrator, I want to deploy a highly available DHCP server in Azure so that I can provide DHCP services to my on-premises network. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +# Deploy a DHCP server in Azure on a virtual machine |
| 16 | + |
| 17 | +Learn how to deploy a highly available DHCP server in Azure on a virtual machine. This server is used as a target for an on-premises DHCP relay agent to provide dynamic IP address allocation to on-premises clients. Broadcast packets directly from clients to a DHCP Server don't work in an Azure Virtual Network by design. |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio). |
| 22 | + |
| 23 | +[!INCLUDE [virtual-network-create-with-bastion.md](../../includes/virtual-network-create-with-bastion.md)] |
| 24 | + |
| 25 | +## Create internal load balancer |
| 26 | + |
| 27 | +In this section, you create an internal load balancer that load balances virtual machines. An internal load balancer is used to load balance traffic inside a virtual network with a private IP address. |
| 28 | + |
| 29 | +During the creation of the load balancer, you configure: |
| 30 | + |
| 31 | +* Frontend IP address |
| 32 | +* Backend pool |
| 33 | +* Inbound load-balancing rules |
| 34 | + |
| 35 | +1. In the search box at the top of the portal, enter **Load balancer**. Select **Load balancers** in the search results. |
| 36 | + |
| 37 | +1. In the **Load balancer** page, select **Create**. |
| 38 | + |
| 39 | +1. In the **Basics** tab of the **Create load balancer** page, enter, or select the following information: |
| 40 | + |
| 41 | + | Setting | Value | |
| 42 | + | --- | --- | |
| 43 | + | **Project details** | | |
| 44 | + | Subscription | Select your subscription. | |
| 45 | + | Resource group | Select **test-rg**. | |
| 46 | + | **Instance details** | | |
| 47 | + | Name | Enter **load-balancer** | |
| 48 | + | Region | Select **(US) East US 2**. | |
| 49 | + | SKU | Leave the default **Standard**. | |
| 50 | + | Type | Select **Internal**. | |
| 51 | + | Tier | Leave the default **Regional**. | |
| 52 | + |
| 53 | +1. Select **Next: Frontend IP configuration** at the bottom of the page. |
| 54 | + |
| 55 | +1. In **Frontend IP configuration**, select **+ Add a frontend IP configuration**. |
| 56 | + |
| 57 | +1. Enter **frontend-1** in **Name**. |
| 58 | + |
| 59 | +1. Select **subnet-1 (10.0.0.0/24)** in **Subnet**. |
| 60 | + |
| 61 | +1. In **Assignment**, select **Static**. |
| 62 | + |
| 63 | +1. In **IP address**, enter **10.0.0.100**. |
| 64 | + |
| 65 | +1. Select **Add**. |
| 66 | + |
| 67 | +1. Select **Next: Backend pools** at the bottom of the page. |
| 68 | + |
| 69 | +1. In the **Backend pools** tab, select **+ Add a backend pool**. |
| 70 | + |
| 71 | +1. Enter **backend-pool** for **Name** in **Add backend pool**. |
| 72 | + |
| 73 | +1. Select **NIC** or **IP Address** for **Backend Pool Configuration**. |
| 74 | + |
| 75 | +1. Select **Save**. |
| 76 | + |
| 77 | +1. Select the blue **Review + create** button at the bottom of the page. |
| 78 | + |
| 79 | +1. Select **Create**. |
| 80 | + |
| 81 | +## Configure second load balancer frontend |
| 82 | + |
| 83 | +A second frontend is required for the load balancer to provide high availability for the DHCP server. Use the following steps to add a second frontend to the load balancer. |
| 84 | + |
| 85 | +1. In the Azure portal, search for and select **Load balancers**. |
| 86 | + |
| 87 | +1. Select **load-balancer**. |
| 88 | + |
| 89 | +1. In **Settings**, select **Frontend IP configuration**. |
| 90 | + |
| 91 | +1. Select **+ Add**. |
| 92 | + |
| 93 | +1. Enter or select the following information in **Add frontend IP configuration**: |
| 94 | + |
| 95 | + | Setting | Value | |
| 96 | + | --- | --- | |
| 97 | + | **Name** | Enter **frontend-2**. | |
| 98 | + | **Subnet** | Select **subnet-1 (10.0.0.0/24)**. | |
| 99 | + | **Assignment** | Select **Static**. | |
| 100 | + | **IP address** | Enter **10.0.0.200**. | |
| 101 | + | **Availability zone** | Select **Zone-redundant**. | |
| 102 | + |
| 103 | +1. Select **Add**. |
| 104 | + |
| 105 | +1. Verify that in **Frontend IP configuration**, you have **frontend-1** and **frontend-2**. |
| 106 | + |
| 107 | +## Create load balancer rules |
| 108 | + |
| 109 | +The load balancer rules are used to distribute traffic to the virtual machines. Use the following steps to create the load balancer rules. |
| 110 | + |
| 111 | +1. In the Azure portal, search for and select **Load balancers**. |
| 112 | + |
| 113 | +1. Select **load-balancer**. |
| 114 | + |
| 115 | +1. In **Settings**, select **Load balancing rules**. |
| 116 | + |
| 117 | +1. Select **+ Add**. |
| 118 | + |
| 119 | +1. Enter or select the following information in **Add load balancing rule**: |
| 120 | + |
| 121 | + | Setting | Value | |
| 122 | + | --- | --- | |
| 123 | + | **Name** | Enter **lb-rule-1**. | |
| 124 | + | **IP version** | Select **IPv4**. | |
| 125 | + | **Frontend IP address** | Select **frontend-1**. | |
| 126 | + | **Backend pool** | Select **backend-pool**. | |
| 127 | + | **Protocol** | Select **UDP**. | |
| 128 | + | **Port** | Enter **67**. | |
| 129 | + | **Backend port** | Enter **67**. | |
| 130 | + | **Health probe** | Select **Create new**. </br> Enter **dhcp-health-probe** for **Name**. </br> Select **TCP** for **Protocol**. </br> Enter **3389** for **Port**. </br> Enter **67** for **Interval**. </br> Enter **5** for **Unhealthy threshold**. </br> Select **Save**. | |
| 131 | + | **Enable Floating IP** | Select the box. | |
| 132 | + |
| 133 | +1. Select **Save**. |
| 134 | + |
| 135 | +1. Repeat the previous steps to create the second load balancing rule. Replace the following values with the values for the second frontend: |
| 136 | + |
| 137 | + | Setting | Value | |
| 138 | + | --- | --- | |
| 139 | + | **Name** | Enter **lb-rule-2**. | |
| 140 | + | **Frontend IP address** | Select **frontend-2**. | |
| 141 | + | **Health probe** | Select **dhcp-health-probe**. | |
| 142 | + |
| 143 | +[!INCLUDE [create-two-virtual-machines-windows-load-balancer.md](../../includes/create-two-virtual-machines-windows-load-balancer.md)] |
| 144 | + |
| 145 | +## Configure DHCP server network adapters |
| 146 | + |
| 147 | +You'll sign-in to the virtual machines with Azure Bastion and configure the network adapter settings and DHCP server role for each virtual machine. |
| 148 | + |
| 149 | +1. In the Azure portal, search for and select **Virtual machines**. |
| 150 | + |
| 151 | +1. Select **vm-1**. |
| 152 | + |
| 153 | +1. In the **vm-1** page, select **Connect** then **Connect via Bastion**. |
| 154 | + |
| 155 | +1. Enter the username and password you created when you created the virtual machine. |
| 156 | + |
| 157 | +1. Open **PowerShell** as an administrator. |
| 158 | + |
| 159 | +1. Run the following command to install the DHCP server role: |
| 160 | + |
| 161 | + ```powershell |
| 162 | + Install-WindowsFeature -Name DHCP -IncludeManagementTools |
| 163 | + ``` |
| 164 | +
|
| 165 | +### Install Microsoft Loopback Adapter |
| 166 | +
|
| 167 | +Use the following steps to install the Microsoft Loopback Adapter by using the Hardware Wizard: |
| 168 | +
|
| 169 | +1. Open **Device Manager** on the virtual machine. |
| 170 | +
|
| 171 | +1. Select the computer name **vm-1** in **Device Manager**. |
| 172 | +
|
| 173 | +1. In the menu bar, select **Action** then **Add legacy hardware**. |
| 174 | +
|
| 175 | +1. In the **Add Hardware Wizard**, select **Next**. |
| 176 | +
|
| 177 | +1. Select **Install the hardware that I manually select from a list (Advanced)**, and then select **Next** |
| 178 | +
|
| 179 | +1. In the **Common hardware types** list, select **Network adapters**, and then select **Next**. |
| 180 | +
|
| 181 | +1. In the **Manufacturers** list box, select **Microsoft**. |
| 182 | +
|
| 183 | +1. In the **Network Adapter** list box, select **Microsoft Loopback Adapter**, and then select **Next**. |
| 184 | +
|
| 185 | +1. select **Next** to start installing the drivers for your hardware. |
| 186 | +
|
| 187 | +1. select **Finish**. |
| 188 | +
|
| 189 | +1. In **Device Manager**, expand **Network adapters**. Verify that **Microsoft Loopback Adapter** is listed. |
| 190 | +
|
| 191 | +1. Close **Device Manager**. |
| 192 | +
|
| 193 | +### Set static IP address for Microsoft Loopback Adapter |
| 194 | +
|
| 195 | +Use the following steps to set a static IP address for the Microsoft Loopback Adapter: |
| 196 | +
|
| 197 | +1. Open **Network and Internet settings** on the virtual machine. |
| 198 | +
|
| 199 | +1. Select **Change adapter options**. |
| 200 | +
|
| 201 | +1. Right-click **Microsoft Loopback Adapter** and select **Properties**. |
| 202 | +
|
| 203 | +1. Select **Internet Protocol Version 4 (TCP/IPv4)** and select **Properties**. |
| 204 | +
|
| 205 | +1. Select **Use the following IP address**. |
| 206 | +
|
| 207 | +1. Enter the following information: |
| 208 | +
|
| 209 | + | Setting | Value | |
| 210 | + | --- | --- | |
| 211 | + | **IP address** | Enter **10.0.0.100**. | |
| 212 | + | **Subnet mask** | Enter **255.255.255.0**. | |
| 213 | +
|
| 214 | +1. Select **OK**. |
| 215 | +
|
| 216 | +1. Select **Close**. |
| 217 | +
|
| 218 | +### Enable routing between the loopback interface and the network adapter |
| 219 | +
|
| 220 | +Use the following steps to enable routing between the loopback interface and the network adapter: |
| 221 | +
|
| 222 | +1. Open **CMD** as an administrator. |
| 223 | +
|
| 224 | +1. Run the following command to list the network interfaces: |
| 225 | +
|
| 226 | + ```cmd |
| 227 | + netsh int ipv4 show int |
| 228 | + ``` |
| 229 | +
|
| 230 | + ```output |
| 231 | + C:\Users\azureuser>netsh int ipv4 show int |
| 232 | +
|
| 233 | + Idx Met MTU State Name |
| 234 | + --- ---------- ---------- ------------ --------------------------- |
| 235 | + 1 75 4294967295 connected Loopback Pseudo-Interface 1 |
| 236 | + 6 5 1500 connected Ethernet |
| 237 | + 11 25 1500 connected Ethernet 3 |
| 238 | + ``` |
| 239 | +
|
| 240 | + In this example, the network interface connected to the Azure Virtual network is **Ethernet**. The loopback interface that you installed in the previous section is **Ethernet 3**. |
| 241 | +
|
| 242 | + **Make note of the `Idx` number for the primary network adapter and the loopback adapter. In this example the primary network adapter is `6` and the loopback adapter is `11`. You'll need these values for the next steps.** |
| 243 | +
|
| 244 | + > [!CAUTION] |
| 245 | + > Don't confuse the **Loopback Loopback Pseudo-Interface 1** with the **Microsoft Loopback Adapter**. The **Loopback Pseudo-Interface 1** isn't used in this scenario. |
| 246 | +
|
| 247 | +1. Run the following command to enable **weakhostreceive** and **weakhostsend** on the primary network adapter: |
| 248 | +
|
| 249 | + ```cmd |
| 250 | + netsh int ipv4 set int 6 weakhostreceive=enabled weakhostsend=enabled |
| 251 | + ``` |
| 252 | +
|
| 253 | +1. Run the following command to enable **weakhostreceive** and **weakhostsend** on the loopback adapter: |
| 254 | +
|
| 255 | + ```cmd |
| 256 | + netsh int ipv4 set int 11 weakhostreceive=enabled weakhostsend=enabled |
| 257 | + ``` |
| 258 | +
|
| 259 | +1. Close the bastion connection to **vm-1**. |
| 260 | +
|
| 261 | +1. Repeat the previous steps to configure **vm-2**. Replace the IP address of **10.0.0.100** with **10.0.0.200** in the static IP address configuration of the loopback adapter. |
| 262 | +
|
| 263 | +## Next step |
| 264 | +
|
| 265 | +In this article, you learned how to deploy a highly available DHCP server in Azure on a virtual machine. You also learned how to configure the network adapters and installed the DHCP role on the virtual machines. Further configuration of the DHCP server is required to provide DHCP services to on-premises clients from the Azure Virtual Machines. The DHCP relay agent on the on-premises network must be configured to forward DHCP requests to the DHCP servers in Azure. Consult the manufacturer's documentation for the DHCP relay agent for configuration steps. |
0 commit comments