Bird
Raised Fist0
Azurecloud~5 mins

Azure SQL firewall rules - Commands & Configuration

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Azure SQL firewall rules control which IP addresses can connect to your Azure SQL database. They help protect your database by allowing only trusted computers to access it.
When you want to allow your office computer to access the Azure SQL database securely.
When you need to let a web server in a specific IP range connect to your database.
When you want to block all access except from certain trusted IP addresses.
When you are setting up a new Azure SQL database and need to configure access.
When you want to allow your home IP address to connect temporarily for maintenance.
Commands
This command creates a firewall rule named AllowOfficeIP that allows the single IP address 203.0.113.5 to access the Azure SQL server. It is run first to open access for that IP.
Terminal
az sql server firewall-rule create --resource-group example-group --server example-sql-server --name AllowOfficeIP --start-ip-address 203.0.113.5 --end-ip-address 203.0.113.5
Expected OutputExpected
{ "endIpAddress": "203.0.113.5", "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-group/providers/Microsoft.Sql/servers/example-sql-server/firewallRules/AllowOfficeIP", "name": "AllowOfficeIP", "startIpAddress": "203.0.113.5", "type": "Microsoft.Sql/servers/firewallRules" }
→
--resource-group - Specifies the Azure resource group where the SQL server exists
→
--server - Specifies the name of the Azure SQL server
→
--start-ip-address - Defines the starting IP address allowed by the rule
→
--end-ip-address - Defines the ending IP address allowed by the rule
This command lists all firewall rules for the specified Azure SQL server to verify the rule was created successfully.
Terminal
az sql server firewall-rule list --resource-group example-group --server example-sql-server
Expected OutputExpected
[ { "endIpAddress": "203.0.113.5", "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-group/providers/Microsoft.Sql/servers/example-sql-server/firewallRules/AllowOfficeIP", "name": "AllowOfficeIP", "startIpAddress": "203.0.113.5", "type": "Microsoft.Sql/servers/firewallRules" } ]
→
--resource-group - Specifies the Azure resource group where the SQL server exists
→
--server - Specifies the name of the Azure SQL server
This command deletes the firewall rule named AllowOfficeIP to remove access for that IP address when it is no longer needed.
Terminal
az sql server firewall-rule delete --resource-group example-group --server example-sql-server --name AllowOfficeIP
Expected OutputExpected
No output (command runs silently)
→
--resource-group - Specifies the Azure resource group where the SQL server exists
→
--server - Specifies the name of the Azure SQL server
→
--name - Specifies the name of the firewall rule to delete
This command lists all firewall rules again to confirm the rule was deleted and access is revoked.
Terminal
az sql server firewall-rule list --resource-group example-group --server example-sql-server
Expected OutputExpected
[]
→
--resource-group - Specifies the Azure resource group where the SQL server exists
→
--server - Specifies the name of the Azure SQL server
Key Concept

If you remember nothing else from this pattern, remember: Azure SQL firewall rules let you control which IP addresses can connect to your database to keep it safe.

Common Mistakes
Setting the start IP address higher than the end IP address
The firewall rule will not work because the IP range is invalid and no IPs will be allowed.
Always set the start IP address to be the same or lower than the end IP address.
Not specifying the correct resource group or server name
The command will fail or modify the wrong server's firewall rules.
Double-check the resource group and server name before running commands.
Forgetting to delete temporary firewall rules after use
Leaving open firewall rules can expose your database to unwanted access.
Remove firewall rules when they are no longer needed to maintain security.
Summary
Create firewall rules to allow specific IP addresses access to your Azure SQL server.
List firewall rules to verify which IPs have access.
Delete firewall rules to remove access when it is no longer needed.

Practice

(1/5)
1. What is the main purpose of Azure SQL firewall rules?
easy
A. To control which IP addresses can access the database
B. To encrypt data stored in the database
C. To backup the database automatically
D. To monitor database performance

Solution

  1. Step 1: Understand firewall rules function

    Azure SQL firewall rules specify which IP addresses are allowed to connect to the database.
  2. Step 2: Compare with other options

    Encryption, backup, and monitoring are different features not controlled by firewall rules.
  3. Final Answer:

    To control which IP addresses can access the database -> Option A
  4. Quick Check:

    Firewall rules = control IP access [OK]
Hint: Firewall rules control IP access, not encryption or backup [OK]
Common Mistakes:
  • Confusing firewall rules with encryption settings
  • Thinking firewall rules manage backups
  • Assuming firewall rules monitor performance
2. Which of the following is the correct way to define a firewall rule in Azure SQL?
easy
A. Specify a username and password
B. Specify only a single IP address without a range
C. Specify a start IP and an end IP address range
D. Specify a database name and region

Solution

  1. Step 1: Recall firewall rule structure

    Azure SQL firewall rules require a start IP and an end IP to define the allowed range.
  2. Step 2: Eliminate incorrect options

    Single IP alone is not enough; username/password and database name/region are unrelated to firewall rules.
  3. Final Answer:

    Specify a start IP and an end IP address range -> Option C
  4. Quick Check:

    Firewall rule = start IP + end IP [OK]
Hint: Firewall rules need IP ranges, not usernames or database names [OK]
Common Mistakes:
  • Trying to use usernames instead of IP addresses
  • Defining only one IP without a range
  • Confusing firewall rules with database settings
3. Given a firewall rule with start IP 192.168.1.10 and end IP 192.168.1.20, which IP address can connect?
medium
A. 192.168.1.9
B. 192.168.2.10
C. 192.168.1.21
D. 192.168.1.15

Solution

  1. Step 1: Understand IP range inclusion

    The firewall rule allows IPs from 192.168.1.10 up to 192.168.1.20 inclusive.
  2. Step 2: Check each IP against the range

    192.168.1.9 is below start IP, 192.168.1.15 is inside range, 192.168.1.21 and 192.168.2.10 are outside the range.
  3. Final Answer:

    192.168.1.15 -> Option D
  4. Quick Check:

    IP inside range = allowed [OK]
Hint: Check if IP is between start and end IP inclusive [OK]
Common Mistakes:
  • Choosing IP just outside the range
  • Ignoring inclusive range boundaries
  • Confusing similar IP addresses
4. You created a firewall rule with start IP 10.0.0.5 and end IP 10.0.0.3. What is the problem?
medium
A. The rule allows all IPs by mistake
B. Start IP is greater than end IP, so the rule is invalid
C. The IP addresses are in different subnets
D. There is no problem; the rule is valid

Solution

  1. Step 1: Check IP range order

    The start IP must be less than or equal to the end IP for a valid range.
  2. Step 2: Identify invalid range

    Here, 10.0.0.5 is greater than 10.0.0.3, making the range invalid.
  3. Final Answer:

    Start IP is greater than end IP, so the rule is invalid -> Option B
  4. Quick Check:

    Start IP ≤ End IP for valid rule [OK]
Hint: Start IP must be less or equal to end IP [OK]
Common Mistakes:
  • Ignoring IP order in the range
  • Assuming different subnets cause errors
  • Thinking invalid range allows all IPs
5. You want to allow access only from your office IP 203.0.113.25 and your home IP 198.51.100.10. How should you configure Azure SQL firewall rules?
hard
A. Create two separate firewall rules, each with start and end IP set to one of the IPs
B. Create one firewall rule with start IP 198.51.100.10 and end IP 203.0.113.25
C. Create one firewall rule with start IP 0.0.0.0 and end IP 255.255.255.255
D. Create a firewall rule with start IP 198.51.100.10 and end IP 198.51.100.10 only

Solution

  1. Step 1: Understand IP range rules

    Firewall rules allow ranges of IPs; to allow two separate IPs, create two rules each with start and end IP the same.
  2. Step 2: Evaluate options

    Create two separate firewall rules, each with start and end IP set to one of the IPs correctly creates two rules for each IP. Create one firewall rule with start IP 198.51.100.10 and end IP 203.0.113.25 creates a large range including unwanted IPs. Create one firewall rule with start IP 0.0.0.0 and end IP 255.255.255.255 allows all IPs, which is insecure. Create a firewall rule with start IP 198.51.100.10 and end IP 198.51.100.10 only allows only one IP, missing the other.
  3. Final Answer:

    Create two separate firewall rules, each with start and end IP set to one of the IPs -> Option A
  4. Quick Check:

    Separate IPs need separate rules [OK]
Hint: Use separate rules for separate IPs, same start and end IP [OK]
Common Mistakes:
  • Trying to combine non-contiguous IPs in one rule
  • Allowing all IPs by mistake
  • Creating only one rule for multiple IPs