官术网_书友最值得收藏!

Configuring firewall rules

Each SQL Server instance running on your server is using a different port number to listen for incoming connections, but during the installation of the SQL Server, there are no firewall rules created on your local firewall. So SQL Server is perfectly accessible locally, but not from remote hosts if the local firewall is active. You can run with a built-in firewall on the Windows Servers or have some third-party software in your environment, which requires additional configuration.

During the installation of the SQL Server, you had to make a choice between deploying SQL Server as a default instance or a named instance. SQL Server default instance is listening on port 1433, which you can verify in the SQL Server configuration manager tool. This port is set as static and will not change over time. Named instances, on the other hand, use a randomly selected port, which may not be fixed and can change after a system reboot, because named instances use dynamic ports as a default option.

It's advised to change the dynamic port to static so that the port number does not change and this does not have any impact for any security configuration like service principal name, which we'll discuss in another chapter.

The following screenshot gives a good idea of the default instances:

Once we know what port our SQL Server instance is listening to, we need to configure the firewall to allow the traffic to our SQL Server service. Windows Server comes with a built-in firewall that can be controlled via GUI, command line, and PowerShell.

We will add three different rules to the firewall with the PowerShell tool:

  • The first rule is for the SQL Server service with the proper port number. We have seen the port number in the configuration manager. For a default instance, this is 1433; for a named instance, the port number would be mostly random on each system.
  • The second rule is used for dedicated admin connection, which is used for troubleshooting the system. Enabling just the firewall rule does not allow you to remotely connect to DAC session; this also has to be turned on in the SQL Server configuration and we'll cover this topic later.
  • The third rule is for a service called SQL Server browser, which is used for connection to the named instances:
New-NetFirewallRule -DisplayName “SQL Server Connection” –Protocol TCP -Direction Inbound –LocalPort 1433 -Action allow
New-NetFirewallRule -DisplayName “SQL Server DAC Connection” –Protocol TCP -Direction Inbound –LocalPort 1434 -Action allow
New-NetFirewallRule -DisplayName “SQL Server Browser Service” –Protocol UDP -Direction Inbound –LocalPort 1434 -Action allow

If you're running more instances on the server, or any other services such as analysis services or reporting services, or you use any solutions for HA/DR such as mirroring or always on, then you need to carefully examine what firewall rules are needed and the list may get much longer than the three basic rules we have seen.

主站蜘蛛池模板: 台安县| 夹江县| 巴南区| 公安县| 革吉县| 策勒县| 保定市| 军事| 肃北| 绥中县| 佛山市| 嘉峪关市| 铜陵市| 斗六市| 忻州市| 武威市| 崇左市| 天峨县| 东安县| 建瓯市| 黑龙江省| 陵川县| 西安市| 安仁县| 新巴尔虎右旗| 通化县| 施秉县| 进贤县| 抚远县| 乌兰县| 琼海市| 清涧县| 北宁市| 渑池县| 三都| 沭阳县| 晴隆县| 兴海县| 太和县| 镇平县| 黄梅县|