Configuring NLB with PowerShell

It’s actually possible to do most NLB configuration in PowerShell. Here are some leads and a sample script.

First, let’s install the NLB Role (this is a DOS command)

Ocsetup.exe NetworkLoadBalancingFullServer

Next, this powershell script will create an NLB Cluster on the current host. It assumes your NLB interface is named “NLB”. Note: DedicatedIP is optional and not all that useful.

Import-Module NetworkLoadBalancingClusters
#create the cluster
New-NlbCluster -ClusterName "" -ClusterPrimaryIP  -SubnetMask  -DedicatedIP  -DedicatedIPSubnetMask  -OperationMode "igmpmulticast" -interfaceName "NLB" -force
#Remove all cluster port rules
Get-NLBClusterPortRule | Remove-NlbClusterPortRule -Force
#Add a new port rule allowing port 80
Add-NlbClusterPortRule -mode multiple -affinity single -startport 80 -endport 80 -protocol tcp -interfaceName "NLB"

The following powershell script will add the current host (referred to as nlb2) to the cluster on NLB1.domain.com.

Import-Module NetworkLoadBalancingClusters

#Add host
(Get-NLBCluster -hostname nlb1.domain.com) | Where-Object {$_.Name -eq ""} | `
	Add-NLBClusterNode -NewNodeName "nlb2" -newNodeInterface "NLB" -force

#remove default DIP
(Get-NlbClusterNodeDip -nodename nlb2) | Remove-NlbClusterNodeDip -force

#add proper DIP
Add-NlbClusterNodeDip -hostname nlb2 -interfacename "NLB" -IP  -subnetmask 

Finally, we can change some settings on the interfaces (more dos).

REM Disable unneeded protocols
nvspbind.exe /d "NLB" ms_tcpip6
nvspbind.exe /d "NLB" ms_netbt
nvspbind.exe /d "NLB" ms_smb
nvspbind.exe /d "NLB" ms_lltdio
nvspbind.exe /d "NLB" ms_rspndr
nvspbind.exe /d "NLB" ms_pppoe

REM Set DNS Servers on NLB Interface
netsh interface ipv4 add dnsserver name="NLB" address=xxx.xxx.xxx.xxx index=1
netsh interface ipv4 add dnsserver name="NLB" address=xxx.xxx.xxx.xxx index=2

REM Set Gateway on NLB Interface
netsh interface ipv4 add address "NLB" gateway=xxx.xxx.xxx.xxx gwmetric=2

REM Set Interface Metrics on Interfaces
netsh interface ipv4 set interface "NLB" metric=2
netsh interface ipv4 set interface "eth0, LAN Network" metric=1

Hope this helps you do something cool! JP

Advertisements

One thought on “Configuring NLB with PowerShell

  1. Pingback: Windows NLB (network load balancing) resources « Jacques DALBERA's IT world

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s