0

I want to connect to a remote AzureDB server (which has ip address ip2 and hostname "abc.database.windows.net" ) from my local computer(which has ip address ip1). However, my local host can't directly access to DB server, so I had to use SSH Tunnel via a jump server (which has ip3 and able to access to AzureDB server) for connecting. Here is what i was doing:

1, Create SSH Tunnel:

ssh -v -g -N -C -L local-port:**ip2**:1433 ssh-user@**ip3** -p 22

2, Connect to to DB server

sqlcmd -S 127.0.0.1,local-port -U db-user@**abc**.database.windows.net -P password -d db-name

But i got the error:

Cannot open server 'abc' requested by the login. Client with IP address 'ip1' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.

I checked the tunnel connection with telnet and no error has been showed up. Can anyone tell me what's wrong with my work?

Kenster
  • 23,465
  • 21
  • 80
  • 106
lee dan
  • 1
  • 1

1 Answers1

1

If we want to access the remote Azure SQL database, make sure you have add the local IP 'ip1' to the Azure SQL Server firewall on Portal:

enter image description here

Please try bellow command:

ssh -L local_port:abc.database.windows.net:1433 db-user@abc.database.windows.net

sqlcmd -S 127.0.0.1,local-port -U db-user@**abc**.database.windows.net -P password -d db-name

Also reference this blogs:

  1. Unable to reach SQL database through SSH tunnel using sqlcmd
  2. Configuring SSH Tunnels for Database Connections

Hope this helps.

Leon Yue
  • 15,693
  • 1
  • 11
  • 23
  • 1
    Since I couldn't directly access to DB server for security reasons, I need to use a jump server (azure cloudapp server) for tunneling. The 1st reference is a little diffirent from my case, as in error log my ip1 is shown up, not 127.0.0.1. Even a jump server is used, does my ip1 need to be added to Azure SQL Server firewall? DB Server need to be set up to allow SSH connections? – lee dan Mar 26 '20 at 03:27