All Products
Search
Document Center

ApsaraDB RDS:Client public IP for SQL Server

Last Updated:Jun 21, 2026

This topic describes how to identify the actual public IP address of a client when its IP address changes dynamically.

Scenario 1

Problem

Your client has a dynamic public IP address. Local IP lookup tools may report an inaccurate IP address. Even if you add this IP address to the whitelist of your RDS instance, connection errors still occur. To connect to the RDS instance, you must find the correct client IP address.

Notes

If the public IP address of your local device changes in a production environment, we recommend using an internal network connection or configuring an appropriate CIDR block in the whitelist. This practice prevents disconnections caused by IP address changes.

Determine client IP

  1. Add 0.0.0.0/0 to the whitelist of your RDS instance. For more information, see Configure a whitelist.

    Important

    The entry 0.0.0.0/0 allows access from any IP address. You must remove this entry immediately after you complete the test.

  2. Use a client to connect to the ApsaraDB RDS for SQL Server instance. For more information, see Connect to an ApsaraDB RDS for SQL Server instance.

  3. Run the following command to find the client IP address.

    SELECT  CONNECTIONPROPERTY('PROTOCOL_TYPE') AS PROTOCOL_TYPE,
            CONNECTIONPROPERTY('CLIENT_NET_ADDRESS') AS CLIENT_NET_ADDRESS

    In the result, the CLIENT_NET_ADDRESS value is the client's actual IP address.

  4. Remove the 0.0.0.0/0 entry from the whitelist, and add the actual egress IP address.

Scenario 2

Problem

Use the following method to find all IP addresses connected to your ApsaraDB RDS for SQL Server instance or to troubleshoot security issues such as connection leaks.

Find all connected IPs

  1. Add 0.0.0.0/0 to the whitelist of your RDS instance. For more information, see Configure a whitelist.

    Important

    The entry 0.0.0.0/0 allows access from any IP address. You must remove this entry immediately after you complete the test.

  2. Use a client to connect to the ApsaraDB RDS for SQL Server instance. For more information, see Connect to an ApsaraDB RDS for SQL Server instance.

  3. Run the following command to query all IP addresses connected to the database.

    SELECT
    SP.SPID,
    SP.LOGINAME,
    SP.LOGIN_TIME,
    SP.HOSTNAME,
    SP.PROGRAM_NAME,
    DC.CLIENT_TCP_PORT,
    DC.CLIENT_NET_ADDRESS
    FROM SYS.SYSPROCESSES AS SP
    INNER JOIN SYS.DM_EXEC_CONNECTIONS AS DC
    ON SP.SPID = DC.SESSION_ID
    WHERE SP.SPID > 50
    AND DC.AUTH_SCHEME='SQL'
  4. Remove the 0.0.0.0/0 entry from the whitelist.

View detailed connection parameters

After querying all connected IP addresses, run the following command to view detailed parameters for a specific connection:

SELECT * FROM SYS.DM_EXEC_SESSIONS WHERE SESSION_ID=<the previously obtained SPID>

A successful query returns a result set with the detailed parameters for the session. Key columns include session_id, login_time, host_name, program_name, host_process_id, client_version, client_interface_name, security_id, login_name, nt_domain, nt_user_name, and status.