locked
Specifying CLIENT IP Address when connecting with Native IP Library API on system with MANY IP Addresses RRS feed

  • Question

  • HI,

    I am trying to connect to Sql Server on a Remote Server BEHIND A FIREWALL from a VB.NET application.  My client system has 64 IP Addresses.  Only ONE of my client IP addresses has been granted access through the firewall!!!  How can I specify the CLIENT IP Address (from valid choices on the system) in API when connecting to a remote server by IP Address?  In more techno speak, I need to specify the source IP not IPADDR_ANY in the Bind().

    Thanks in advance,

    Sean

    Sunday, March 24, 2013 4:20 PM

Answers

  • The only suggestion I have is to use netsh to specify skipassource=true for the 63 IP addresses you don't want to use for outbound connections.  See http://blogs.technet.com/b/rmilne/archive/2012/02/08/fine-grained-control-when-registering-multiple-ips.aspx for examples.  I don't know if how feasible that is in your environment since I don't know the purpose of the multiple IP addresses.  However, I believe multiple IP addresses on a given interface are usually used only for inbound connections.


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Monday, March 25, 2013 12:52 AM
  • Again, Dan thanks for your help it was a gallant effort.

    I thought I would post my resolution for future readers.  I needed to know the SOURCE IP Address being used when an ASP.NET web application opened an sql connection to a REMOTE server.  We were only allowed 1 address so I had to identify it.  Dan informed me that address is assigned by Windows not SQL Client.  I wrote a web page with code behind that opened a link to www.whatismyipaddress.com and displayed the result to the user viewing my page.  It returned one of the IP addresses from my server.  Adding that single IP Address to the firewall blocking me solved the problem.

    My web page code behind just Imports system.net and System.IO Then in Page_Load put this code:

            Dim request As WebRequest = WebRequest.Create("http://www.whatismyipaddress.com/")
            Dim wresponse As WebResponse = request.GetResponse()

            Dim dataStream As Stream = wresponse.GetResponseStream()
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            Response.Write(responseFromServer)

     The IP Address displayed is the external ip address used by your server for web apps!  There may be flaws in this, but it worked for me.

    Sean

    Monday, March 25, 2013 5:38 PM

All replies

  • It is the operating system rather than the SQL Server client API that determines network routing.  With TCP/IP, you can add a static route so that the desired network interface is used.  Below is a Windows ROUTE ADD command example to use interface 19 and gateway 10.11.12.1 for traffic to remote host 192.11.12.13.  The value for the interface index (19 in this example) can be obtained from the interface list reported by ROUTE PRINT.

    ROUTE /p ADD 192.11.12.13 MASK 255.255.255.255 10.11.12.1 IF 19
    

    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    • Proposed as answer by Papy Normand Sunday, March 24, 2013 6:18 PM
    Sunday, March 24, 2013 5:58 PM
  • GREAT Answer Dan.  BUT I don't have different addresses on different interfaces, I have multiple IP Addresses all on 1 NIC so 1 Interface number!

    Any tricks to get me there?  How can I split a single IP off of the same nic as all the others?

    Sean


    • Edited by Sean Devoy Sunday, March 24, 2013 10:24 PM
    Sunday, March 24, 2013 10:19 PM
  • The only suggestion I have is to use netsh to specify skipassource=true for the 63 IP addresses you don't want to use for outbound connections.  See http://blogs.technet.com/b/rmilne/archive/2012/02/08/fine-grained-control-when-registering-multiple-ips.aspx for examples.  I don't know if how feasible that is in your environment since I don't know the purpose of the multiple IP addresses.  However, I believe multiple IP addresses on a given interface are usually used only for inbound connections.


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Monday, March 25, 2013 12:52 AM
  • Yes, exactly Dan, the multiple addresses is for web sites requiring SSL connections.  This code is part of one of those websites.  I will review the article.

    [UPDATE]

    My first thought was that is would work well.  However, since it is system wide, I believe it will mess with the MAIL Server, the DNS Server and IIS for all those sites with SSLs.  :-(

    Thanks


    • Edited by Sean Devoy Monday, March 25, 2013 12:29 PM
    Monday, March 25, 2013 11:47 AM
  • Again, Dan thanks for your help it was a gallant effort.

    I thought I would post my resolution for future readers.  I needed to know the SOURCE IP Address being used when an ASP.NET web application opened an sql connection to a REMOTE server.  We were only allowed 1 address so I had to identify it.  Dan informed me that address is assigned by Windows not SQL Client.  I wrote a web page with code behind that opened a link to www.whatismyipaddress.com and displayed the result to the user viewing my page.  It returned one of the IP addresses from my server.  Adding that single IP Address to the firewall blocking me solved the problem.

    My web page code behind just Imports system.net and System.IO Then in Page_Load put this code:

            Dim request As WebRequest = WebRequest.Create("http://www.whatismyipaddress.com/")
            Dim wresponse As WebResponse = request.GetResponse()

            Dim dataStream As Stream = wresponse.GetResponseStream()
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            Response.Write(responseFromServer)

     The IP Address displayed is the external ip address used by your server for web apps!  There may be flaws in this, but it worked for me.

    Sean

    Monday, March 25, 2013 5:38 PM