lee dan
lee dan

Reputation: 1

Cannot connect to remote AzureDB server via SSH Tunnel

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?

Upvotes: 0

Views: 1111

Answers (1)

Leon Yue
Leon Yue

Reputation: 16431

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 [email protected]

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.

Upvotes: 1

Related Questions