Introduction
Network Load Balancing (NLB) in Windows Server allows you to distribute network traffic across multiple servers, ensuring high availability and reliability for applications such as web servers or RDS gateways. While the GUI is functional, configuring NLB via PowerShell is faster, more reproducible, and essential for Server Core deployments. This guide walks you through installing the NLB feature, creating a cluster, and adding nodes strictly using PowerShell.
Prerequisites
Before proceeding, ensure you have the following:
- At least two Windows Server instances (e.g., Server 2019 or 2022) with static IP addresses.
- A dedicated IP address to act as the Cluster IP.
- Administrative privileges on all participating nodes.
Step 1: Install the NLB Feature
First, you must install the NLB feature on all servers that will join the cluster. Open PowerShell as Administrator on each node and run:
Install-WindowsFeature -Name NLB -IncludeManagementTools
Wait for the installation to complete. A reboot is typically not required, but you should verify the Success property in the output.
Step 2: Create the NLB Cluster on the First Node
On your primary server, you will create the new cluster and assign it the shared Cluster IP address. Use the New-NlbCluster cmdlet:
New-NlbCluster -InterfaceName "Ethernet" -ClusterName "WebCluster" -ClusterPrimaryIP 192.168.1.100 -SubnetMask 255.255.255.0 -OperationMode Multicast
Note: Replace "Ethernet" with the actual name of your network adapter. You can find this using Get-NetAdapter. The OperationMode can be Unicast, Multicast, or IGMPMulticast depending on your switch configuration.
Step 3: Add Port Rules
By default, NLB routes all traffic. To restrict it to specific ports (e.g., Port 80 and 443 for web traffic), configure port rules.
Get-NlbCluster | Add-NlbClusterPortRule -StartPort 80 -EndPort 80 -Protocol TCP -Affinity Single
The Single affinity ensures that requests from the same client IP are routed to the same cluster node, which is crucial for session persistence.
Step 4: Join Additional Nodes to the Cluster
Once the cluster is running on the first node, log into the second node (or run this remotely). Use the Add-NlbClusterNode cmdlet to join the cluster:
Add-NlbClusterNode -InterfaceName "Ethernet" -NewNodeName "Server02" -NewNodeInterface "Ethernet" -HostName "192.168.1.100"
Here, 192.168.1.100 is the Cluster IP you defined in Step 2. The second node will connect and begin participating in load balancing.
Troubleshooting Common NLB Issues
If the nodes fail to communicate, verify your OperationMode. Multicast requires static ARP entries on some routers, while Unicast alters the MAC address of the adapter, potentially causing connectivity drops if you only have one NIC per server. Use Get-NlbClusterNode to verify that all nodes are in a Converged state.