Configure Firewall Settings on Azure SQL
Firewall rules in Azure SQL Database control which IP addresses can connect to your database server. Configuring these rules correctly ensures that only trusted users and applications access your data while keeping it secure from unauthorized traffic.
Azure provides two levels of firewall configuration: server-level and database-level rules. Server-level rules allow access to all databases under a logical server, while database-level rules apply only to a specific database.
You can configure firewall rules using the Azure Portal, Transact-SQL (T-SQL) commands, or PowerShell. Understanding how and where to apply these rules helps ensure a secure and flexible environment for managing database access.
Azure SQL uses a layered firewall model:
- Server-level firewall rules: These define allowed IP address ranges for the entire logical SQL server. Any database under that server inherits these settings.
- Database-level firewall rules: These are stored within an individual database and apply only to connections to that database.
When to use each:
- Use server-level rules when multiple databases need the same IP access.
- Use database-level rules when access needs to be restricted to specific databases or when users lack server-level permissions.
Example:
- Allowing your organization’s office IP to access all databases? → Use server-level.
- Granting temporary access to a consultant for one database? → Use database-level.
Reference: Rishan Digital – Firewall Rules and Authentication
You can create firewall rules in Azure SQL using T-SQL commands or directly in the Azure Portal.
Using T-SQL (Server-level example):
EXECUTE sp_set_firewall_rule
@name = 'AllowOfficeIP',
@start_ip_address = '203.0.113.0',
@end_ip_address = '203.0.113.0';
For a database-level rule:
EXECUTE sp_set_database_firewall_rule
@name = 'AllowDevMachine',
@start_ip_address = '198.51.100.10',
@end_ip_address = '198.51.100.10';
Tip: Always double-check the IP range and limit access to only the addresses that genuinely need it to avoid overly broad access.
Source: SQLShack – Configure IP Firewall Rules for Azure SQL Databases
Comments