21

What's the simplest way to check connectivity from a Linux server (e.g. Ubuntu 18.04) to a remote Microsoft SQL Server 2017 instance?

3 Answers 3

18

I think the simplest would be to try to telnet to MS SQL server from the command line:

$ telnet <server-name-or-ip> 1433

If your connection was successful the screen goes blank, otherwise you'll see something like "Connecting to server-name-or-ip... Could not open connection to the host, on port 1433: Connect failed."

1
  • so this is what a negative test?
    – Bozojoe
    Oct 9, 2020 at 0:47
11

Another easy way would be to use nc (netcat) from the command line:

nc -zv YOUR_SERVER_NAME_OR_IP 1433

If a connection can be established, you should see an output like this:

Connection to YOUR_SQL_SERVER_NAME_OR_IP 1433 port [tcp/ms-sql-s] succeeded!

On failure, you get different error messages depending on the cause:

nc: getaddrinfo for host "NON_EXISTING_SQL_SERVER_NAME_OR_IP" port 1433: Name or service not known

or maybe...

nc: connect to YOUR_SQL_SERVER_NAME_OR_IP port 143 (tcp) failed: Connection timed out

From nc man page, z and v options are:

     -z      Specifies that nc should just scan for listening daemons, without sending any
             data to them.  It is an error to use this option in conjunction with the -l
             option.
     -v      Have nc give more verbose output.
9

On the remote Microsoft SQL Server instance: make sure port TCP 1433 is open in the firewall.

On the Ubuntu Server instance install the mssql-tools as described here: https://www.microsoft.com/en-us/sql-server/developer-get-started/php/ubuntu

sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17 mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
sudo apt-get install unixodbc-dev

You can then run a test query - you'll be prompted for password:

[user@lnx01 ~ $] sqlcmd -S <remoteip> -U <user> -p -Q "SELECT @@VERSION"
Password: 

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64) 
    Aug 22 2017 17:04:49 
    Copyright (C) 2017 Microsoft Corporation
    Express Edition (64-bit) on Windows Server 2016 Standard 10.0 <X64> (Build 14393: )


(1 rows affected)
2
  • 1
    when creating/editing ~/.bash_profile the colours are removed from the shell (ie the user@host$ no longer has a colour). To avoid this you can send to ~/.profile instead. Dec 3, 2020 at 19:58
  • 1
    This works ok, but mind the 2nd curl line, and check the provided link Chef Tony provides, so you download the correct version.
    – mistige
    Jul 27, 2021 at 10:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .