How to allow ODBC to connect to SQL via and external IP

AID: 5229
  • Status: Published

8090 points

  • ByBilbo3D
  • TypeTutorial
  • Posted on2011-04-09 at 18:49:40
Awards
  • Experts Exchange Approved
Setting up SQL to use an external IP can give you flexability to access a database without opening up a VPN tunnel or full fledged RDP session. This is particularly useful for low bandwidth clients that have a poor internet connection or are being charged for bandwidth used.

***WARNING***
This will open up ports in your firewall. You will want to take precautionary steps to be sure that you are not making your network and/or server vulnerable to attack. I will show you a few ways you can protect yourself when using this method.

Let's get started

First, I'm going to check to make sure that my SQL settings will allow remote connections.

Open SQL Server Management Studio. Right click on the server and select Properties. This will show you the IP your SQL Server is using.
 
1SSSMProperties.png
  • 31 KB
  • SQL Server Management Studio
SQL Server Management Studio


Open SQL Server Configuration Manager. Expand the SQL Server 2005 Network Configuration menu and highlight the "Protocols for MSSQLSERVER". Make sure that TCP/IP is enabled.
 
3ConnectionManagerTCPIP.png
  • 11 KB
  • SQL Server Configuration Manager
SQL Server Configuration Manager


Right click on the "TCP/IP" and select Properties.
 
4PropertiesDialog.png
  • 4 KB
  • TCP/IP Properties
TCP/IP Properties


Click on the "IP Addresses" Tab.
You should see 3  different entries: IP1, IP2, and IPAll. Usually IP1 will be your external IP, IP2 will be your internal IP.

You can specify the external IP here. I have chosen the IP 198.113.113.113 (not a real IP) I will use the IP in later steps.
You can also specify the port that will be used. I will use the default port of 1433 for this example.

*TIP: Use a custom port to help with security. Make sure to use the same port here and in the later firewall steps.
 
6TCPIP-IPAddresses.png
  • 6 KB
  • IP and Port Specification
IP and Port Specification


Next, open the Surface Area Configuration and click on MSSQLSERVER, expand the Database Engine, and click on Remote Connections. Make sure that the "Local and remote connections" option is selected. In the submenu, you can select either "Using TCP/IP only" or "Using both TCP/IP and named pipes"
 
7SurfaceAreaConfigRemoteConnecti.png
  • 44 KB
  • Surface Area Configuration
Surface Area Configuration


Now an important step that is often overlooked and can be the source of much confusion.
Open the Services by going to Start-> All Programs -> Administrative Tools -> Services
Make sure that SQL Server and SQL Browser services are started and are set to start automatically. Even if all the settings are correct, if the Browser service is not started, it will fail.
 
8Services.png
  • 35 KB
  • Services
Services


Now I need to configure my firewall to allow the connection. I am using a Netgear FVX358.

Click on "Security" and then on "Services"

I will add a service and name it "Real Data Plus". I will make it a TCP type and since I only want to open one port, I will make the "Starting Port" and "Ending Port" the same, the default 1433. If you used a custom port in the SQL settings, you will need to use the same custom port here.
 
9RouterServices.png
  • 52 KB
  • Router Settings
Router Settings


Now, I navigate to the "Firewall" menu, still under the "Security" settings.
Click on the "LAN WAN Rules" tab. Under the "Outbound policy" add a new entry. Be sure to name it the same as the Rule in the above step, in my case "Real Data Plus". Enter the internal address you want the traffic to be redirected to and the external ip the traffic will be coming from.
*TIP: For added security, specify the IP address or range that the traffic will be coming from. The firewall will block all others.
 
10RouterFirewallMenu.png
  • 29 KB
  • Firewall Menu
Firewall Menu
11RouterFirewallEntry.png
  • 6 KB
  • Firewall Entry
Firewall Entry


To test to make sure a connection can be made through the external IP open a command prompt and type the following command without the quotes: "sqlcmd -S 198.113.113.113,1433 -U sa" (Of course, use your own IP and port number) You will prompted for a password. Once you enter it, if you get the 1> prompt, you have successfully been connected. Type "EXIT". If you do not get this prompt, you are not able to be connected so something is not opened properly.
 
12SQLCMD.png
  • 13 KB
  • Telnet connection test
Telnet connection test


To test the port forwarding through the firewall, I used the website http://yougetsignal.com/tools/open-ports I entered the external address of 198.113.113.113 and the port 1433 and it came back to tell me that my port is opened or closed. This is useful, as then you know if it is a SQL problem or a firewall problem.
 
13PortCheck.png
  • 115 KB
  • Port Check
Port Check



If all goes well, you will now be able to set up your ODBC using the external IP and port. Happy databasing!
    Asked On
    2011-04-09 at 18:49:40ID5229
    Tags

    sql server odbc

    Topic

    MS SQL Server

    Views
    2857

    Comments

    Author Comment

    by: Bilbo3D on 2011-04-09 at 19:29:39ID: 25630

    Thank you very much! :D

    Expert Comment

    by: Qlemo on 2011-04-10 at 05:00:14ID: 25634

    That setup has an unnecessary step - you need not to define the external IP in MSSQL, as communication will take part using the internal IP. Only if the public IP would be routed directly thru (like usually in a DMZ), that step would be needed.
    Further, if you change IP settings for MSSQL, you need to restart the services to have them applied.

    Author Comment

    by: Bilbo3D on 2011-04-10 at 12:31:02ID: 25640

    Qlemo,
    Thank you for your comments. I agree, you don't always have to specify the IP in MSSQL but doing so will eliminate any doubt that it is listening on the correct IP and port. Also, good point in the restarting of services. I should have mentioned that when I was checking to make sure the services were running. Thank you!

    Expert Comment

    by: Qlemo on 2011-04-10 at 14:52:19ID: 25641

    " but doing so will eliminate any doubt that it is listening on the correct IP and port!
    Sorry, but that is not true at all. You can enter whatever you want there - if it isn't used, it has no value. I fear it is rather misleading then helpful.

    Expert Comment

    by: Sandeepiii on 2011-04-25 at 22:07:54ID: 26051

    Qlemo:can you plz explain Only if the public IP would be routed directly thru (like usually in a DMZ), that step would be needed.with a example..thanks

    Expert Comment

    by: Qlemo on 2011-04-26 at 09:01:18ID: 26056

    It's quite simple: If you have a public IP assigned on your MSSQL server, and that machine has more than one IP, and that public IP is routed thru the the Internet routing device to that machine, then you have to setup the public IP and port in the MSSQL network settings.
    The same applies if you need another port (different from the "local" one) on the machine.

    Any other scenario is handled automatically - MSSQL binds to all network adapters (and their first IP address), with the default port or one determined automatically, if not configured to be fixed.

    In short: If the router does all the work, that is translatiing the public IP and port to the internal IP and port, you do not need to configure a second IP in MSSQL network config. And that is the configuration used most of time.

    Add your Comment

    Please Sign up or Log in to comment on this article.

    Join Experts Exchange Today

    Gain Access to all our Tech Resources

    Get personalized answers

    Ask unlimited questions

    Access Proven Solutions

    Search 3.2 million solutions

    Read In-Depth How-To Guides

    1000+ articles, demos, & tips

    Watch Step by Step Tutorials

    Learn direct from top tech pros

    And Much More!

    Your complete tech resource

    See Plans and Pricing

    30-day free trial. Register in 60 seconds.

    Loading Advertisement...

    Top MS SQL Server Experts

    1. jogos

      246,566

      Guru

      1,668 points yesterday

      Profile
      Rank: Sage
    2. acperkins

      246,249

      Guru

      1,000 points yesterday

      Profile
      Rank: Genius
    3. lcohan

      194,990

      Guru

      2,000 points yesterday

      Profile
      Rank: Genius
    4. anujnb

      179,525

      Guru

      2,000 points yesterday

      Profile
      Rank: Wizard
    5. ScottPletcher

      154,405

      Guru

      6,500 points yesterday

      Profile
      Rank: Genius
    6. matthewspatrick

      131,392

      Master

      1,620 points yesterday

      Profile
      Rank: Savant
    7. ValentinoV

      126,429

      Master

      1,800 points yesterday

      Profile
      Rank: Genius
    8. EugeneZ

      120,790

      Master

      2,000 points yesterday

      Profile
      Rank: Genius
    9. TempDBA

      112,141

      Master

      1,168 points yesterday

      Profile
      Rank: Sage
    10. angelIII

      100,133

      Master

      0 points yesterday

      Profile
      Rank: Elite
    11. HainKurt

      93,046

      Master

      0 points yesterday

      Profile
      Rank: Genius
    12. mwvisa1

      88,585

      Master

      40 points yesterday

      Profile
      Rank: Genius
    13. dtodd

      88,114

      Master

      0 points yesterday

      Profile
      Rank: Genius
    14. huslayer

      81,392

      Master

      0 points yesterday

      Profile
      Rank: Sage
    15. ralmada

      75,583

      Master

      400 points yesterday

      Profile
      Rank: Genius
    16. BCUNNEY

      74,206

      Master

      0 points yesterday

      Profile
      Rank: Guru
    17. dqmq

      66,272

      Master

      0 points yesterday

      Profile
      Rank: Genius
    18. rajeevnandanmishra

      60,246

      Master

      2,000 points yesterday

      Profile
      Rank: Guru
    19. dbaduck

      58,208

      Master

      2,000 points yesterday

      Profile
      Rank: Sage
    20. CodeCruiser

      55,120

      Master

      0 points yesterday

      Profile
      Rank: Genius
    21. Qlemo

      53,598

      Master

      2,000 points yesterday

      Profile
      Rank: Genius
    22. ryanmccauley

      52,252

      Master

      0 points yesterday

      Profile
      Rank: Sage
    23. Cluskitt

      50,880

      Master

      800 points yesterday

      Profile
      Rank: Wizard
    24. sdstuber

      50,836

      Master

      0 points yesterday

      Profile
      Rank: Genius
    25. mark_wills

      49,374

      10 points yesterday

      Profile
      Rank: Genius

    Hall Of Fame