本文介绍如何在 SMB 客户端和服务器组件上启用或禁用服务器消息块(SMB)版本 1(SMBv1)、SMB 版本 2(SMBv2)和 SMB 版本 3(SMBv3)。
如果禁用或删除 SMBv1,则可能会遇到旧计算机或软件的兼容性问题。 SMBv1 存在严重的安全漏洞,强烈建议不要使用它。 默认情况下,SMBv1 在任何版本的 Windows 11 或 Windows Server 2019 及更高版本中都未安装。 默认情况下,SMBv1 也不会在 Windows 10 中安装,但家庭版和专业版除外。 建议不要重新安装 SMBv1,而是更新仍需要它的 SMB 服务器。 有关需要使用 SMBv1 的合作伙伴及其移除 SMBv1 要求的更新,请参阅 SMB1 产品信息库。
禁用 SMBv2 或 SMBv3 以排除故障
我们建议保持启用 SMBv2 和 SMBv3,但你可能发现,暂时禁用其中一个版本可以方便进行故障排除。 有关详细信息,请参阅 使用命令行或注册表编辑器管理 SMB 协议。
禁用 SMBv3 会停用以下功能:
- 在维护或故障转移期间,透明故障转移为客户端提供了一种不中断地重新连接到群集节点的方法。
- 横向扩展:提供对所有文件群集节点上共享数据的并发访问
- SMB 多通道:如果客户端和服务器之间提供了多个路径,则有助于聚合网络带宽和容错
- SMB 直通:支持远程直接内存访问(RDMA)网络以实现高性能、低延迟和低 CPU 使用率
- 加密:提供端到端加密,并提供对不可信网络上窃听的保护
- 目录租赁:通过缓存改进分支机构的应用程序响应时间
- 性能优化:优化小型随机读/写I/O操作
禁用 SMBv2 会停用以下功能:
- 请求复合:支持以单个网络请求的形式发送多个 SMBv2 请求
- 更高的读取和写入速度:改善对更快网络的利用
- 缓存文件夹和文件属性:使客户端能够保留文件夹和文件的本地副本
- 持久句柄:为连接在暂时断开后以透明方式重新连接服务器提供了一种方法
- 改进了信息签名:使用基于散列的消息验证码 (HMAC) 安全散列算法 (SHA),以 256 位摘要 (HMAC SHA-256) 代替消息加密算法 5 (MD5) 作为散列算法
- 改进了文件共享的可伸缩性:大大增加了每个服务器的用户数、共享和打开文件数
- 支持符号链接
- 客户端 oplock 租赁模型:限制客户端和服务器之间传输的数据,提高高延迟网络的性能并提高 SMB 服务器可伸缩性
- 最大最大传输单元(MTU)支持:支持充分利用 10 千兆位以太网(GbE)
- 提高能效:为服务器上打开文件的客户端提供一种休眠方式
SMBv2 协议是在 Windows Vista 和 Windows Server 2008 中引入的。 SMBv3 协议是在 Windows 8 和 Windows Server 2012 中引入的。 有关 SMBv2 和 SMBv3 功能的详细信息,请参阅以下文章:
- Windows Server 中使用 SMB 3 协议的文件共享概述
- 1.3 Overview
使用 PowerShell 删除 SMBv1
You can use the Get-WindowsOptionalFeature, Disable-WindowsOptionalFeature, and Enable-WindowsOptionalFeature PowerShell commands to detect, disable, and enable an SMBv1 client or server. 在权限提升的命令提示符下运行以下命令。
Note
运行 PowerShell 命令以禁用或启用 SMBv1 后,计算机将重启。
Detect:
Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
Disable:
Disable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
Enable:
Enable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
Tip
You can detect the SMBv1 status without elevation by running the Get-SmbServerConfiguration command: Get-SmbServerConfiguration | Format-List EnableSMB1Protocol
.
Remove SMBv1
默认情况下,SMBv1 不会安装在 Windows Server 2019 及更高版本上。 在早期版本的 Windows Server 上,可以使用服务器管理器删除 SMBv1:
在要从中删除 SMBv1 的服务器上,打开服务器管理器。
在“服务器管理器仪表板”“配置此本地服务器”下,选择“添加角色和功能。
在“开始之前”页上选择“启动‘删除角色和功能’向导”,然后在随后出现的页上选择“下一步”。
在“选择目标服务器” 页上,在“服务器池”下,确保选择要从中删除该功能的服务器,然后选择“下一步”。
在“删除服务器角色”页上,选择“下一步”。
On the Remove features page, clear the checkbox for SMB 1.0/CIFS File Sharing Support, and then select Next.
在“确认删除所选内容”页上,确认已列出该功能,然后选择“删除”。
使用命令行或注册表编辑器管理 SMB 协议
从 Windows 10 Fall Creators Update 和 Windows Server 2019 开始,默认情况下不再安装 SMBv1。 有关详细信息,请参阅 windows 10 版本 1709、Windows Server 版本 1709 及更高版本 中默认未安装SMBv1。
在 Windows 8 或 Windows Server 2012 中启用或禁用 SMBv2 时,也会启用或禁用 SMBv3。 出现此行为是因为这些协议共享同一个堆栈。
You can use the Set-SMBServerConfiguration cmdlet to enable or disable the SMBv1, SMBv2, and SMBv3 protocols on a server component. You can use the Get-SmbServerConfiguration cmdlet to retrieve the SMB server configuration.
You don't have to restart the computer after you run the Set-SMBServerConfiguration cmdlet.
SMBv1
Detect:
Get-SmbServerConfiguration | Select EnableSMB1Protocol
Disable:
Set-SmbServerConfiguration -EnableSMB1Protocol $false
Enable:
Set-SmbServerConfiguration -EnableSMB1Protocol $true
有关详细信息,请参阅 停止使用 SMB1。
SMBv2 和 SMBv3
Detect:
Get-SmbServerConfiguration | Select EnableSMB2Protocol
Disable:
Set-SmbServerConfiguration -EnableSMB2Protocol $false
Enable:
Set-SmbServerConfiguration -EnableSMB2Protocol $true
在 Windows 7、Windows Server 2008 R2、Windows Vista 和 Windows Server 2008 上启用或禁用 SMB
若要在运行 Windows 7、Windows Server 2008 R2、Windows Vista 或 Windows Server 2008 的 SMB 服务器上启用或禁用 SMB 协议,请使用 Windows PowerShell 或注册表编辑器,如以下部分所述。
使用 Windows PowerShell
You can use the Get-Item, Get-ItemProperty, and Set-ItemProperty cmdlets to detect, enable, and disable SMB protocols.
Note
以下部分中的命令需要 PowerShell 2.0 或更高版本。
SMB 服务器上的 SMBv1
Detect:
Get-Item HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters | ForEach-Object {Get-ItemProperty $_.pspath}
默认配置为
Enabled
。 因此,不会创建任何注册表命名值,因此该命令不会返回SMB1
值。Disable:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" SMB1 -Type DWORD -Value 0 -Force
Enable:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" SMB1 -Type DWORD -Value 1 -Force
Note
进行这些更改后,必须重启计算机。
有关详细信息,请参阅 停止使用 SMB1。
SMB 服务器上的 SMBv2 和 SMBv3
Detect:
Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters | ForEach-Object {Get-ItemProperty $_.pspath}
Disable:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" SMB2 -Type DWORD -Value 0 -Force
Enable:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" SMB2 -Type DWORD -Value 1 -Force
Note
进行这些更改后,必须重启计算机。
使用注册表编辑器
Important
请认真遵循本部分所述的步骤。 如果注册表修改不正确,可能会发生严重问题。 在修改注册表之前,请备份注册表,以便在出现问题时可以还原。
若要在 SMB 服务器上启用或禁用 SMBv1,请打开注册表编辑器并转到以下注册表项路径:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
配置具有以下属性的条目:
- For the name, use SMB1.
- For the type, use REG_DWORD.
- For the data, use 0 for Disabled and 1 for Enabled. The default value is 1, or Enabled. 在这种情况下,不会创建注册表项目。
若要在 SMB 服务器上启用或禁用 SMBv2,请打开注册表编辑器并转到以下注册表项路径:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
配置具有以下属性的条目:
- For the name, use SMB2.
- For the type, use REG_DWORD.
- For the data, use 0 for Disabled and 1 for Enabled. The default value is 1, or Enabled. 在这种情况下,不会创建注册表项目。
Note
进行这些更改后,必须重启计算机。
使用组策略禁用 SMBv1
本部分介绍如何使用组策略禁用 SMBv1。 可以在各种版本的 Windows 上使用此方法。
SMBv1
可以通过在注册表中配置以下新项,在 SMB 服务器上禁用 SMBv1:
- Key path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
- Registry entry: SMB1
- Entry type: REG_DWORD
- Entry data: 0, for Disabled
若要使用组策略配置此项,请执行以下步骤:
打开组策略管理控制台。 Right-click the Group Policy object (GPO) that should contain the new preference item, and then select Edit.
In the console tree under Computer Configuration, expand the Preferences folder, and then expand the Windows Settings folder.
Right-click the Registry node, point to New, and then select Registry Item.
在 “新建注册表属性” 对话框中,选择或输入以下值:
- Action: Create
- Hive: HKEY_LOCAL_MACHINE
- Key Path: SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
- Value name: SMB1
- Value type: REG_DWORD
- Value data: 0
此过程禁用 SMBv1 服务器组件。 必须将此策略应用于域中所有必要的工作站、服务器和域控制器。
Note
你可以设置 Windows Management Instrumentation (WMI) 筛选器以排除特定作系统或排除客户端或服务器作系统。 有关详细信息,请参阅 组策略筛选 和 为 GPO创建 WMI 筛选器。
Important
某些系统需要访问 SYSVOL 文件夹或其他文件共享,但不支持 SMBv2 或 SMBv3。 此类系统的示例包括旧版 Windows 系统和旧版 Linux 和合作伙伴系统。 在这些系统上的域控制器上禁用 SMBv1 时,请小心。
审核 SMBv1 使用情况
若要确定哪些客户端尝试使用 SMBv1 连接到 SMB 服务器,可以在 Windows Server 和 Windows 客户端上启用审核。 To enable or disable auditing, use the Set-SmbServerConfiguration cmdlet. To check the auditing status, use the Get-SmbServerConfiguration cmdlet.
Enable:
Set-SmbServerConfiguration -AuditSmb1Access $true
Disable:
Set-SmbServerConfiguration -AuditSmb1Access $false
Detect:
Get-SmbServerConfiguration | Select AuditSmb1Access
启用 SMBv1 审核后,可以检查 Microsoft-Windows-SMBServer\Audit
事件日志中是否有访问事件。 每次客户端尝试使用 SMBv1 连接到服务器时,日志中都会显示一个事件 ID 为 3000 的条目。
检查组策略设置
如果所有设置都位于同一 GPO 中,组策略管理将显示以下设置:
测试和验证策略
组策略配置时,请完成组策略管理控制台中的所有步骤后,给组策略留出一定的时间以将更新应用到设置。 如果需要进行测试,请在命令提示符处运行 gpupdate /force
,然后查看目标计算机以确保正确应用注册表设置。 确保 SMBv2 和 SMBv3 可对环境中的所有其他系统正常运行。
Note
测试策略后,重启目标系统。