In this article, we covered three network file-sharing protocols and their differences.
Table of Contents
windows 目录共享和网络共享的区别,适用用场景
目录共享:单机内部。指的是同一个电脑上给不同用户设置权限,共享重点在单机多用户。
网络共享:跨局域网PC。允许局域网内其他计算机(如PC2, PC3)访问本机(PC1)的共享资源。把文件夹分享给局域网内的其他设备。共享重点在是跨PC设备。
网络路径访问:格式为 \\计算机名\共享名或 \\IP地址\共享名
目录访问权限
目录共享(NTFS权限)
权限基础
NTFS权限(非常精细,可控制到用户/用户组的具体操作:读、写、执行、删除等)
当你在一台电脑上创建多个用户账户时,可以通过设置文件夹的“安全”属性,精确控制“谁”(哪个用户或用户组)可以“做什么”(读取、修改、完全控制等)。
公司公共电脑:一台电脑,销售部、财务部的员工轮流使用。可以设置:
D:\销售数据:只允许“销售组”用户读写,财务组用户无法访问。
D:\财务报表:只允许“财务组”用户读写,销售组用户无法访问。
网络共享 (SMB共享)
基于 SMB/CIFS 协议 的服务,让一台计算机将本地文件夹“发布”到网络上,供其他计算机访问。
当通过网络访问一个共享文件夹时:
1.网络身份验证:
用户必须提供有效的用户名和密码。
2.用户会经历 两道权限检查:
身份验证成功后,系统会两道权限检查。
共享权限(第一道门):决定你是否能进入共享点。共享权限(相对简单,通常只有“读”、“更改”、“完全控制”几个级别)
NTFS权限(第二道门,在共享文件夹内部的真实文件上):决定你进来后能对里面的具体文件做什么。
最终有效权限是两者中最严格的限制。
小结
一个完整的的网络共享方案,必需同时使用这两种技术。
步骤:
1.先设置好目录共享文件夹的 NTFS权限(本地、本机目录共享,精细化控制)
2.然后再开启 网络共享(设置共享名和共享权限,作为网络入口)。
3.为避免权限冲突,常见的做法是:在共享权限中设置为 “Everyone - 完全控制”(或“读取/写入”),而将真正的精细权限控制全部交给文件夹的 NTFS权限(安全选项卡)
具体配置:
目录共享权限:设置为 "Everyone - 完全控制"
NTFS权限:设置详细的用户/组权限(如:财务组-读取,管理员-完全控制)
这样,所有访问控制都通过NTFS权限统一管理,避免了双重检查的复杂性。
访问协议
First, we defined Distributed File Systems, which raised the question of which protocol is more convenient for file sharing. Then, we briefly covered the NFS, SMB, and CIFS protocols before identifying their differences.
We observed that CIFS is an obsolete SMB implementation; therefore, NFS and SMB must be the best options to consider.
NFS (Network File System) is a file-sharing protocol primarily used in Unix-like operating systems. This protocol consists of a client and an NFS server as the central repository of files and directories.
Samba is made by linux/unix。是一种局域网共享协议
SMB/CIFS is made by windows/microsoft。SMB (Server Message Block) protocol is file-sharing protocol used in Windows systems. The authentication system is user-based. That is, a client’s IP address doesn’t grant or deny access but user credentials do.
SMB is commonly used for print-sharing capabilities. In other words, the SMB protocol allows printers to be shared as network resources.
CIFS
CIFS (Common Internet File System), is an implementation of the SMB protocol. Microsoft developed CIFS solely based on the original version of SMB, called SMB1. Consequently, later versions of SMB provide more capabilities and enhancements than the CIFS implementation.
Samba
SMB 最早是微软为自己需求设计的专用协议,用来实现微软主机之间的文件共享与打印共享,并不支持在 Linux 上运行。
著名黑客、技术大牛 Andrew Tridgell 通过逆向工程,在 Linux 上实现的 SMB / CIFS 兼容协议,命名为 Samba,通过该程序实现了 Windows 和 Linux 之间的文件共享
所以,Samba 是 SMB(Server Message Block / Common Internet File System)网络协议在 Linux 上的重新实现,可以在局域网不同计算机之间进行文件、打印机等资源共享,和 NFS 功能类似。
Differences Between NFS, SMB, and CIFS
| NFS | SMB | CIFS | |
|---|---|---|---|
| Environment | NFS (Network File System) is a file-sharing protocol primarily used in Unix-like operating systems | SMB is made by windows/microsoft。SMB (Server Message Block) protocol is file-sharing protocol used in Windows systems | CIFS (Common Internet File System), is an implementation of the SMB protocol |
| Cross-Platform | Supported | Supported | Supported |
| Authentication | Host-based Authentication and Kerberos | User-based Authentication and Kerberos | User-based Authentication |
| Encryption | Not enabled by default | AES enabled by default | Not supported |
| File Locking | Advisory and Mandatory locking handled by NLM | Opportunistic locking (oplocks) | Opportunistic locking (oplocks) |
| Network Resources | File sharing and Network Block Devices (NBD) | File sharing and print sharing | File sharing and print sharing |
| Windows 2016 版网络文件系统 (NFS) 提供一个文件共享解决方案,用于通过 NFS 协议在运行 Windows Server 和 UNIX 操作系统的计算机之间传输文件。 | SMB 协议是 C/S 类型协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。通过设置“NetBIOS over TCP/IP” | ||
| detail | detail:https://learn.microsoft.com/zh-cn/windows-server/storage/file-server/file-server-smb-overview |
NFS
使用 NFS,客户端设备可以连接到网络服务器并访问服务器上的文件。该系统具有允许多个用户共享同一个文件而不会发生数据冲突的规则.
什么是 NFS,它如何运作?
网络文件系统(NFS)协议由 Sun Microsystems 于 1984 年创建,是基于 Unix 的系统的有状态文件共享协议。此后,NFS 经历了几次更新。最新版本是 NFS 版本 4(NFSv4),它是由互联网工程任务组的一个工作小组开发的。NFS 在 Linux 用户中仍然很受欢迎。
以下是启用 NFS 的客户端与 NFS 服务器之间的通信方式。首先,客户端使用远程过程调用(RPC)向服务器请求文件或目录。然后,服务器会检查以下内容:
文件或目录可用
客户端具有所需的访问权限
然后,服务器将文件或目录远程安装在客户端上,并通过虚拟连接共享访问权限。对于客户端,NFS 像在操作期间访问本地文件一样使用远程服务器文件。
除其他功能外,NFS 客户端还可以缓存文件以提高访问速度,锁定多台计算机尝试同时写入的同一个文件,并提供同步的文件属性更新。
SMB
服务器消息区块(英语:Server Message Block,缩写为SMB,服务器消息区块),又称网络文件共享系统(英语:Common Internet File System,缩写为CIFS),一种应用层网络传输协议,由微软开发,主要功能是使网络上的机器能够计算机文件、打印机、串行端口和通讯等资源。它也提供经认证的进程间通信机能。它主要用在装有Microsoft Windows的机器上,在这样的机器上被称为Microsoft Windows Network。
SMB 允许用户读取服务器上的文件。但是,它可以提供更大的灵活性,因此客户端也可以相互共享文件。客户端可以使用 SMB 与任何其他联网设备(如打印机或文件服务器)建立连接。然后,客户端可以像访问客户端本地文件一样访问设备的文件。
什么是 SMB,它如何运作?
自首次开发服务器消息块(SMB)协议以来,已经经历了几次不同的迭代。它由 IBM 的 Barry Feigenbaum 于 1983 年发布,适用于 DOS 操作系统,即 Windows 的前身。通过与 Windows 产品套件深度集成,SMB 仍然作为 Windows 操作系统的默认文件共享协议。
SMB 的当前版本是 SMB 3.1.1,过去的版本包括 SMB 1.0、SMB 2.0、SMB 2.1、SMB 3.0 和 SMB 3.0.2。SMB 曾经更名为 CIFS(Common Internet File System,通用互联网文件系统),但是,这一名称更改最终被恢复。
客户端-服务器通信的过程大体上与 NFS 类似,区别在于前者的细节和操作机制更加精细。例如,在 SMB 中,文件系统不安装在本地 SMB 客户端,而是通过网络路径访问托管在 SMB 服务器上的网络共享。
文件系统创建完成后,用户需在客户端挂载文件共享,在本地共享目录和CSG的文件共享建立映射,通过操作本地的目录实现对CSG共享目录的操作,实现数据实时上云管理。
CIFS
CIFS (Common Internet File System), is an implementation of the SMB protocol. Microsoft developed CIFS solely based on the original version of SMB, called SMB1. Consequently, later versions of SMB provide more capabilities and enhancements than the CIFS implementation.
When Microsoft released CIFS, some of the improvements included direct client-server communication bypassing NetBIOS. Also, CIFS enabled multiple connections from a single client to the same or multiple servers.
Because CIFS is no longer developed, there are various improvements in later versions of SMB that are not present in CIFS. We can find better performance, security and encryption, and compatibility among these features.
Currently, CIFS is disabled by default in modern Windows systems.
部分yys可能会屏蔽139、445端口,导致广域网无法访问共享。因此,Windows云服务器文件共享方案建议仅在内网环境下使用。
确保“Tcp/IP NetBIOS Helper”服务状态为“已启动”。打开cmd窗口执行命令services.msc,找到TCP/IP NetBIOS

source:https://learn.microsoft.com/en-us/windows-server/storage/file-server/troubleshoot/media/troubleshooting-smb-2.png
Conclusion
Install File Server & File Server Resource Manager(SMB)
SMB 由 windows server 2016 Install file server 提供
安装成功后,系统启动LanManServer。
访问方式身份检查有三种:
凭据传递:使用当前登录的Windows凭据
显式输入:输入目标计算机的账号密码
Guest账户:如果启用了Guest且共享允许匿名访问
useful links
https://www.baeldung.com/cs/file-sharing-nfs-vs-smb-vs-cifs
https://aws.amazon.com/cn/compare/the-difference-between-nfs-smb/
