Specify Source IP for iSCSI initiator on Windows 2008/2008R2 using iscsicli

iscsiwindows-command-prompt

I have two NIC's that have access to my iSCSI network. I want to specify the initiator IP as well as the Target portal IP and create redundant links and use MPIO.

This is easily done using the Advanced settings in the iSCSI initiator GUI. However, I want to be able to specify the initiator IP using iscsicli.

I am pretty sure the answer is in one of the options for iscsicli persistentlogin where there are 15 "*'s" that represent different options. I am just not sure what * to replace with what.

Best Answer

The trick is set the "port number" parameter in the AddTargetPortal command in iscsicli.

However, the only way I was able to associate this port number with an actual IP address is using WMI. In order to figure this out, I used PowerShell

Function Get-IscsiPortNumber {

$query = "select portalinformation from msIsci_portalinfoclass"                                       
$portalInfo = get-wmiobject -namespace root\wmi -query $query
$eScriptBlock ={([Net.IPAddress]$_.ipaddr.IPV4Address).IPAddressToString}
$customLabel = @{Label="IpAddress"; expression = $eScriptBlock}
$portalInfo.portalInformation | select port,$customlabel

}

Once you track down the port number (let's say 2) you can use the following to add the target portal assuming the target has an ip of 10.10.10.10. The port number comes after the initiator name, ROOT\ISCSIPRT\0000_0

iscsicli addtargetportal 10.10.10.10 3260 ROOT\ISCSIPRT\0000_0 2 * * * * * * * * * *