Tuesday, November 6, 2012

Add Remote IPS in a Load balanced Recieve Connector

Here i am posting this because this issue i faced in real time environment.We wanted to have a load balanced recieve conector for application mail relay.So multiple servers recieve connector in Exchange 2010 will be load balanced and provided one common name and Loadbalancer VIP assigned to all these Recieve connector.
The major challange is we are giving permission on ip based.So whenever request comes we need to add those ips in all our Exchange 2010 Hubtransport which meant for this relay.Another challenge is if you add the ips using powershell it will remove old ips and mentioned ip only will be available in remoteips tab.After Long research i found below solution.

If you want to add multiple ips then you can put those ips in a file and run below script which will take the ips from file and add it to your recieve connector.

$RecvConn = Get-ReceiveConnector "exch1\relay-connector1"
Get-Content .\newips.txt | foreach {$RecvConn.RemoteIPRanges += "$_"}
Set-ReceiveConnector "exch1\relay-connector1" -RemoteIPRanges $RecvConn.RemoteIPRanges
Set-ReceiveConnector "exch2\relay-connector1" -RemoteIPRanges $RecvConn.RemoteIPRanges


like wise if you have more than 2 servers
Here newips.txt is the file wher you want to insert ip addresses.Then save above script as .ps1 and run from exchange management shell.

Another way of adding ip addresses is it will pompt for ip and you need to provide ip address when prompting it.


$RecvConn = Get-ReceiveConnector "exch1\relay-connector1"
$IP = read-host "Enter IP"
$RecvConn.RemoteIPRanges += $IP
Set-ReceiveConnector "exch1\relay-connector1" -RemoteIPRanges $RecvConn.RemoteIPRanges
Set-ReceiveConnector "exch2\relay-connector1" -RemoteIPRanges $RecvConn.RemoteIPRanges


In the above examples i have given only 2 servers.If you have more servers you can add below lines by changing the server name.

Set-ReceiveConnector "exch3\relay-connector1" -RemoteIPRanges $RecvConn.RemoteIPRanges

1 comment:

  1. David Lockridge • Jayakumar, I took the script you have and expanded it a little. First, we have multiple Hub transport servers so I want to update this on each with the similar function (external relay or internal only). Next, I added a backup of the current settings to a CSV, just in case. Hopefully this helps others as well. It's helped me greatly.
    ######

    # Written By: David Lockridge

    # Date: 11-08-2012

    # Version: 1.0

    # # Original: http://exchangehowto.blogspot.in/2012/11/add-remote-ips-in-load-balanced-recieve.html?goback=.gde_2293547_member_182751912

    # # Description: This script will add multiple IP addresses into

    # the specified receive connectors.

    # # This script is for Internal Only traffic. Change the filter names

    # to match the names of your receive connectors.

    # # Requirements: Requires Exchange Management Shell to run.

    ###### #===========================================================================

    # Set Variables

    #===========================================================================
    $Date = Get-Date -UFormat "%Y%m%d"
    $Report = "C:Temp$Date-RecConnIPs.csv"
    $Connectors = Get-ReceiveConnector |Where {$_.Identity -like "*Allow SMTP*"}
    $INTRecConns = Get-ReceiveConnector |Where {$_.Name -like "*Internal*"}
    $IPs = Get-Content C:TempNewIPs.txt

    #===========================================================================
    # Create Function for Adding IP's to Rec Connector

    #===========================================================================
    Function GetRecConnectorIPs {
    Foreach ($i in $Connectors) {
    $Name = (Get-ReceiveConnector $i).Identity
    $Allowed = [string](Get-ReceiveConnector $i).RemoteIPRanges

    $Results = New-Object PSObject
    $Results | Add-Member NoteProperty "Receive Connector" ($Name)
    $Results | Add-Member NoteProperty "Allowed Server IPs" ($Allowed)
    Write-Output $Results
    }
    }

    Function SetIPs {
    $IPs | Foreach {$INTRecConns.RemoteIPRanges += "$_"}
    Foreach ($Conn in $INTRecConns) {
    Set-ReceiveConnector $Conn -RemoteIPRanges $INTRecConns.RemoteIPRanges
    }
    }


    #===========================================================================
    # Run Command

    #===========================================================================
    GetRecConnectorIPs | Export-Csv $Report -NoTypeInformation
    Write-Host "Receive Connector IP's written to $Report"
    SetIPs

    ReplyDelete