Cannot ping Azure SQL server from WSL2

Adhitya Ravi 0 Reputation points
2023-06-08T09:41:05.32+00:00

I have my flask app running inside WSL2 Ubuntu. The app connects to a Azure SQL server. But the connection fails. I am not even able to ping the azure server from my WSL2 terminal.

The connection and ping works directly from the Windows terminal.

I have already added firewall exceptions for the ipv4 addresses of both my Windows and WSL2 Ubuntu. I have also tried opening the inbound ports for the WSL2 in my Windows Defender. But still when I ping the Azure SQL server, all my packets are lost.

I have browsed Stack Overflow but there are only solutions as to how the WSL2 can connect with the SQL server running on the Windows host. None of the questions address connecting WSL2 to an Azure SQL server.

Any help would be appreciated, thanks!

Azure SQL Database
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. SSingh-MSFT 16,371 Reputation points Moderator
    2023-06-08T11:40:59.7866667+00:00

    Hi Adhitya Ravi • ,

    Welcome to Microsoft Q&A forum and thanks for using Azure Services.

    As I understand, you Cannot ping Azure SQL server from WSL2. We are sorry about the inconvenience you are facing.

    We need to open the ports from the WSL2 please read this article. Here you will find more information about networking and WSL2.

    Please check if you have added the public IP address of your Internet connection to the whitelist of Azure SQL Database firewall. Please read here to know how.

    It could be also related to DNS resolution. If you the server [ServerName].database.windows.net, the ping should fail but when the ping fails it returns the current IP address of the Azure SQL Database server. If you don't see that then the issue may be related to DNS resolution from your computer.

    Here you will find all steps to configure WSL2 to access a SQL Server/SQL Azure instance.

    1. In your connection string, use the IP address from cat /etc/resolv.conf
    2. open the 1433 port in Windows Firewall. Go to New rule - Port - Next - Specific ports: 1433 - Next - Allow - Next - Next - Name "WSL2 sql"
    3. Disconnect all VPN software in Windows (if any) - it might brake WSL2/Windows network connectivity

    Make sure the corporate network allows outbound traffic on port TCP 1433.

    Let us know if above information helps.

    Thank you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.