Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict an SQL Server connection to a specific IP address

Tags:

I want to restrict the connections to my SQL Server instance to specific IP addresses. I want to prevent any connections from any IP addresses except a specific list. Is this something that can be configured in the SQL Server instance or database?

like image 433
mohammedn Avatar asked Aug 19 '11 21:08

mohammedn


People also ask

How do I block an IP address in SQL Server?

In SQL Server Management Studio (SSMS) right click your instance (above your databases) Properties → Security → Login auditing. Make sure the radio button for either [Failed logins only] || [Both failed and successful logins] is selected. Create the process to auto add IP addresses to the firewall.

How do I restrict connections in SQL Server?

Using SQL Server Management StudioSelect the Connections node. Under Connections, in the Max number of concurrent connections box, type or select a value from 0 through 32767 to set the maximum number of users that are allowed to connect simultaneously to the instance of SQL Server. Restart SQL Server.

How do I restrict an IP address?

To restrict login for all users, complete the following steps: Click Restrict login by IP, then click Global restrictions tab . Enter the global IP address ranges (in CIDR notation) in the Restrict global login to allowed IP range field. Click Save configuration.

How do I whitelist an IP address in SQL Server?

Click on Inbound Rules on the left side. In the middle, double-click on MSSQL Server or MySQL Server. Click the Scope tab. At the bottom, under Remote IP Address, click Add and add your IP.


1 Answers

Sounds like something you'd do using the Windows firewall (you can block the SQL Server port(s), and allow exceptions for certain IP addresses).

You could do this with something like a logon trigger that checked the IP address using sys.dm_exec_connections but I think it's a much less desirable option than blocking the traffic outright.

Certainly much tougher to do at the database level.

like image 160
Aaron Bertrand Avatar answered Sep 20 '22 00:09

Aaron Bertrand