FreeBSD 中文社区 2025 第二季度问卷调查
FreeBSD 中文社区(CFC)
VitePress 镜像站QQ 群 787969044视频教程Ⅰ视频教程Ⅱ
  • FreeBSD 操作系统研究导论
  • 中文期刊
  • 状态报告
  • 发行说明
  • 手册
  • 网络文章集锦
  • 笔记本支持报告
  • Port 开发者手册
  • 架构手册
  • 开发者手册
  • 中文 man 手册
  • 文章与书籍
  • UNIX 四分之一世纪
  • Unix 痛恨者手册
  • FreeBSD 操作系统研究导论(第三版:草稿)
  • 编辑日志
  • 贡献指南与开放任务
  • 目录
  • 前言
    • 致读者
    • 致谢
    • 初版序言:好望角与塔吊
    • 再版序言:回到复制粘贴,面向教程本身
    • 三版序言:且有大觉而后知此其大梦也(草稿)
    • 本书的组织结构
    • 本书中使用的一些约定
  • 第 1 章 FreeBSD 初见
    • 1.1 操作系统的历程:UNIX、BSD 和 Linux
    • 1.2 欢迎来到 FreeBSD
    • 1.3 关于 FreeBSD 项目
    • 1.4 George Berkeley(乔治·贝克莱)与 BSD 命名的文化背景
    • 1.5 加州大学伯克利分校和“Fiat Lux”(要有光)
  • 第 2 章 安装 FreeBSD
    • 2.1 安装前的准备工作
    • 2.2 使用 bsdinstall 开始安装
    • 2.3 键盘布局和主机名
    • 2.4 选择安装组件
    • 2.5 分配磁盘空间
    • 2.6 设置 root 密码
    • 2.7 网络设置
    • 2.8 时区、服务、安全、固件和账户
    • 2.9 完成安装
    • 2.10 故障排除
  • 第 3 章 FreeBSD 基础
    • 3.1 Windows 用户迁移指南
    • 3.2 Linux 用户迁移指南
    • 3.3 虚拟控制台和终端
    • 3.4 认识 shell
    • 3.5 命令行基础
    • 3.6 文本编辑器
    • 3.7 用户和基本账户管理
    • 3.8 权限
    • 3.9 sudo 和 doas
    • 3.10 文件系统的挂载和卸载
    • 3.11 磁盘结构
    • 3.12 目录结构
  • 第 4 章 软件管理和系统升级
    • 4.1 FreeBSD 镜像站现状
    • 4.2 更换 FreeBSD 软件源
    • 4.3 gitup 的用法
    • 4.4 使用 pkg 管理二进制包
    • 4.5 使用 Ports 以源代码方式安装软件
    • 4.6 使用 DVD 安装软件
    • 4.7 使用 freebsd-update 更新 FreeBSD
    • 4.8 使用源代码更新 FreeBSD
    • 4.9 使用 pkgbase 更新 FreeBSD
  • 第 5 章 桌面环境
    • 5.1 Intel 和 AMD 显卡驱动
    • 5.2 NVIDIA 显卡驱动
    • 5.3 KDE6
    • 5.4 GNOME
    • 5.5 Mate
    • 5.6 Xfce
    • 5.7 Cinnamon
    • 5.8 Lumina
    • 5.9 LXQt
    • 5.10 Budgie
    • 5.11 CDE
    • 5.12 LXDE
    • 5.13 主题美化
    • 5.14 远程桌面
    • 5.15 启用 root 桌面登录
  • 第 6 章 本地化——i18n/L10n
    • 6.1 本地化环境变量
    • 6.2 Fcitx 输入法框架
    • 6.3 IBus 输入法框架
    • 6.4 五笔输入法
    • 6.5 网络浏览器
    • 6.6 QQ(Linux 版)
    • 6.7 更换字体
    • 6.8 金山 WPS(Linux 版)
    • 6.9 压缩和解压
    • 6.10 微信(Linux 版)
  • 第 7 章 多媒体和外部设备
    • 7.1 音频设备配置
    • 7.2 蓝牙
    • 7.3 打印机
    • 7.4 触摸板
    • 7.5 音频播放器
    • 7.6 视频播放器
    • 7.7 多媒体处理工具
  • 第 8 章 代理服务器
    • 8.1 HTTP 代理
    • 8.2 V2ray
    • 8.3 Mihomo(原 Clash)
    • 8.4 OpenVPN
  • 第 9 章 Jail
    • 9.1 配置 Jail
    • 9.2 更新 jail
    • 9.3 使用 Qjail 管理 Jail
    • 9.4 Linux Jail
  • 第 10 章 虚拟化和容器
    • 10.1 通过 BVCP 以网页管理 BHyve
    • 10.2 使用 bhyve 安装 Windows 11(vm-bhyve)
    • 10.3 Podman
    • 10.4 在 FreeBSD 上安装 VirtualBox
  • 第 11 章 FreeBSD 安装实践
    • 11.1 使用 Hyper-V 安装 FreeBSD
    • 11.2 使用 VMware Workstation Pro 安装 FreeBSD
    • 11.3 使用 Virtual Box 安装 FreeBSD
    • 11.4 手动安装双系统(先安装 FreeBSD)
    • 11.5 手动安装双系统(后安装 FreeBSD)
    • 11.6 基于 Apple M1 & Parallels Desktop 20 安装 FreeBSD
    • 11.7 基于 Apple M1 & VMware Fusion Pro 安装 FreeBSD
    • 11.8 使用 Qemu 安装 RISC-V FreeBSD(基于 x86 Windows)
    • 11.9 云服务器安装 FreeBSD(基于腾讯云轻量云)
    • 11.10 配置 rEFInd(双系统用)
  • 第 12 章 窗口管理器
    • 12.1 bspwm
    • 12.2 IceWM
    • 12.3 i3wm
    • 12.4 Hyprland
    • 12.5 Window Maker
    • 12.6 Fluxbox
  • 第 13 章 FreeBSD 系统管理
    • 13.1 引导界面和虚拟控制台
    • 13.2 管理 FreeBSD 中的服务
    • 13.3 bsdconfig 系统配置工具
    • 13.4 SSH 配置和相关工具
    • 13.5 单用户模式和密码重置
    • 13.6 Grub、UEFI 和 efibootmgr
  • 第 14 章 网络管理
    • 14.1 设置网络
    • 14.2 无线网络
    • 14.3 USB 网络共享(USB tethering)
    • 14.4 TCP 堆栈
  • 第 15 章 FreeBSD 防火墙
    • 15.1 Fail2Ban(基于 IPFW、PF、IPF)
    • 15.2 Packet Filter(PF)
    • 15.3 IPFilter(IPF)
    • 15.4 ipfirewall(IPFW)
  • 第 16 章 服务器
    • 16.1 FTP 服务器
    • 16.2 MinIO 对象存储服务
    • 16.3 Gitlab-EE
    • 16.4 时间服务
    • 16.5 WildFly
    • 16.6 Rsync 同步服务
    • 16.7 Samba 服务器
    • 16.8 NFS 服务器
    • 16.9 Webmin
  • 第 17 章 Web 服务器和监控平台
    • 17.1 Apache
    • 17.2 Nginx
    • 17.3 PHP 8.X
    • 17.4 Zabbix 监控(基于 PostgreSQL)
    • 17.5 NextCloud——基于 PostgreSQL
    • 17.6 Telegraf+InfluxDB+Grafana 监控平台
    • 17.7 AList
    • 17.8 Prometheus 监控部署
    • 17.9 Tomcat
    • 17.10 Caddy
    • 17.11 OnlyOffice(基于 PostgreSQL)
  • 第 18 章 嵌入式平台
    • 18.1 树莓派简介
    • 18.2 树莓派安装 FreeBSD
    • 18.3 树莓派 FreeBSD 配置
    • 18.4 树莓派和 Linux 兼容层
    • 18.5 Radxa X4(x86)
  • 第 19 章 数据库管理
    • 19.1 PostgreSQL
    • 19.2 pgAdmin4
    • 19.3 MySQL 5.X
    • 19.4 MySQL 8.X
    • 19.5 MongoDB 8.0
  • 第 20 章 游戏、科学计算和专业工具
    • 20.1 游戏
    • 20.2 我的世界(Minecraft)
    • 20.3 科研和专业工具
  • 第 21 章 Linux 二进制兼容层
    • 21.1 Linux 兼容层实现
    • 21.2 RockyLinux 兼容层(FreeBSD Port)
    • 21.3 Ubuntu/Debian 兼容层
    • 21.4 ArchLinux 兼容层(基于 ArchLinux bootstrap)
    • 21.5 ArchLinux 兼容层(基于 archlinux-pacman)
    • 21.6 OpenSUSE 兼容层
    • 21.7 Gentoo Linux 兼容层
    • 21.8 Rocky Linux 兼容层
    • 21.9 Slackware Linux 兼容层
    • 21.10 Deepin 兼容层
    • 21.11 故障排除与未竟事宜
  • 第 22 章 开发生态与贡献社区
    • 22.1 如何报告 Bug
    • 22.2 如何开发一个 Port
    • 22.3 如何参与 FreeBSD 开发
    • 22.4 C/C++ 环境的配置
    • 22.5 Java 环境的配置
    • 22.6 QT 环境的配置
    • 22.7 Python 和 VS Code
    • 22.8 Rust/Go 环境的配置
    • 22.9 配置 Shell
    • 22.10 通过 IDA 7 调试 FreeBSD
    • 22.11 如何订阅 FreeBSD 的邮件列表
    • 22.12 code-server 和 clangd
    • 22.13 Node.js
    • 22.14 利用脚本自动生成 BSDlibc 库文本
  • 第 23 章 存储管理和文件系统
    • 23.1 自动挂载文件系统
    • 23.2 ZFS 文件系统
    • 23.3 磁盘扩容和分区调整
    • 23.4 Windows 文件系统
    • 23.5 Swap 交换分区
    • 23.6 Linux 文件系统
  • 第 24 章 DragonFly BSD 入门
    • 24.1 DragonFly BSD 概述
    • 24.2 安装 DragonFly BSD
    • 24.3 配置 DragonFly BSD
  • 第 25 章 TwinCAT/BSD 入门
    • 25.1 TwinCAT/BSD 系统安装和基本配置
    • 25.2 TwinCAT/BSD 开发环境配置
  • 第 26 章 OpenBSD 入门
    • 26.1 OpenBSD 概述
    • 26.2 安装 OpenBSD
    • 26.3 配置 OpenBSD
    • 26.4 OpenBSD 包管理器
    • 26.5 桌面和其他软件
    • 26.6 在 RISC-V 开发板上安装 OpenBSD
    • 26.7 树莓派和 OpenBSD
  • 第 27 章 NetBSD 入门
    • 27.1 NetBSD 概述
    • 27.2 NetBSD 安装图解
    • 27.3 NetBSD 换源和包管理器
    • 27.4 桌面和中文环境常用软件
  • 附录 Ⅰ 计算机概论
    • 存储卡简介
    • 总线接口与协议
    • 网络基础
    • 操作系统
    • MySQL 数据库
  • 附录 Ⅱ 工具与资源
    • 适用于 FreeBSD 的以太网卡、USB 以太网卡和 USB 无线网卡
    • FreeBSD 桌面发行版评述
    • BSD 许可证概览
  • 附录 Ⅲ 文学故事
    • 我与 FreeBSD 的故事
    • 两次告别
    • 小说:大教堂与集市
    • 小说:吾乡何处
    • 小说:你与暗
    • 诗歌选
    • 杂记
  • 附录 Ⅳ 参考文献和术语
    • 参考书目
    • 术语表
由 GitBook 提供支持
LogoLogo

FreeBSD 中文社区(CFC) 2025

在本页
  • 安装 samba
  • 查看安装后说明
  • 配置 samba
  • 将 Samba 设置为域成员
  • 配置静态 IP 地址
  • 配置主机名
  • 配置 DNS
  • 修改 /etc/sysctl.conf
  • 创建 /etc/krb5.conf
  • 修改 /etc/nsswitch.conf
  • 创建 /usr/local/etc/smb4.conf
  • 将 samba 加入到域
  • 使 samba 启动并设置为开机自启动
  • 测试 Kerberos
  • 测试 Winbind
  • 如果 wbinfo 命令显示报错,请执行命令
  • 创建共享文件夹
  • 故障排除与未竞事宜
在GitHub上编辑
导出为 PDF
  1. 第 16 章 服务器

16.7 Samba 服务器

Samba 是对 SMB/CIFS(Server Message Block,服务器消息块)协议的再实现。CIFS(Common Internet File System,通用 Internet 文件系统)是 SMB 的衍生协议。

Samba 也是“桑巴舞”的葡萄牙语/英语对应的单词。有热情奔放的含义。

samba 须开放防火墙的 tcp/139、445 端口;udp/137、138 端口。

安装 samba

  • 使用 pkg 安装:

# pkg install samba420
  • 或使用 Ports 安装:

# cd /usr/ports/net/samba420/ 
# make install clean

查看安装后说明

# pkg info -D samba420
samba420-4.20.7_4:
On install:  # 安装提示:
How to start: http://wiki.samba.org/index.php/Samba4/HOWTO  
如何启动:参见官方指南

* Your configuration is: /usr/local/etc/smb4.conf
* 你的配置文件路径是:/usr/local/etc/smb4.conf

* All the relevant databases are under: /var/db/samba4
* 所有相关数据库位于:/var/db/samba4

* All the logs are under: /var/log/samba4
* 所有日志位于:/var/log/samba4

* Provisioning script is: /usr/local/bin/samba-tool
* # 初始化脚本是:/usr/local/bin/samba-tool

For the working DNS updates you will need to either build dns/bind9* 
# 若需正常使用 DNS 更新功能,你需要:
with the enabled GSSAPI(GSSAPI_MIT5 is recommended) or install        
# 要么构建启用了 GSSAPI(推荐 GSSAPI_MIT5)的 dns/bind9*,
dns/samba-nsupdate package, which is preconfigured with such a support. 
# 要么安装 dns/samba-nsupdate 包,它已预配置了所需支持。

You will need to specify location of the 'nsupdate' command in the    
smb4.conf file:
# 你需要在 smb4.conf 中指定 nsupdate 命令的位置:

    nsupdate command = /usr/local/bin/samba-nsupdate -g  # 示例配置

For additional documentation check: https://wiki.samba.org/index.php/User_Documentation  
# 更多文档请查阅:

Port related bug reports can go to the https://gitlab.com/samba-freebsd/ports/-/issues or  
# 和 FreeBSD port 相关的问题请提交到:

to the FreeBSD Bugzilla https://bugs.freebsd.org/

# 所有 Samba 本身相关的问题请提交到:
All Samba related bug reports should go to the: https://bugzilla.samba.org/  

配置 samba

  • 配置服务

# service samba_server enable
  • 创建 /usr/local/etc/smb4.conf,添加如下内容并保存

[global]
    min protocol = SMB2

[root]
    comment = root's stuff
    path = /root
    public = no
    browseable = yes
    writable = yes
    printable = no
    create mask = 0755

注释说明:

  • [global]:全局配置段,适用于所有共享项。

  • min protocol = SMB2:将最小支持协议限制为 SMB2,以方便高版本 Windows 访问

  • [root]:定义一个名为 root 的共享。

  • comment = root's stuff:该共享的描述信息,Windows 浏览器中可见。

  • path = /root:共享的实际路径是 /root,不推荐在实际环境中共享该目录。

  • public = no:不允许匿名访问(等同于 guest ok = no)。

  • browseable = yes:可在网络邻居中浏览共享。

  • writable = yes:允许客户端对该目录进行写入。

  • printable = no:不是打印机共享。

  • create mask = 0755:新建文件默认权限为 755,所有者读写,组和其他用户只读。


  • 创建 samba root 用户,并配置密码:

# smbpasswd -a root
  • 启动服务

# service samba_server start 
  • 查看 samba 状态:

# service samba_server status
nmbd is running as pid 1520.
smbd is running as pid 1525.
  • 在 Windows 下使用如下命令访问共享文件夹(以实际 IP 为准,照抄不管用!):

技巧

在 Windows 下访问共享文件夹说明:按下 Windows 键 + R(小写 r 也可以)打开“运行”对话框。在对话框中输入以下命令(以实际 IP 地址和共享文件夹名替换示例中的内容):

\\192.168.179.150

输入刚才创建的用户名 root,以及密码:

连接成功:

将 Samba 设置为域成员

环境:freebsd 12

配置静态 IP 地址

使用如下命令配置:

# bsdconfig

配置主机名

在安装系统的时候应该都配置了主机名,你可以在 /etc/rc.conf 查看或编辑设置:

hostname="fb"

配置 DNS

编辑 /etc/resolv.conf,写入:

# Generated by resolvconf
search SVROS.COM               //设置域控制器域名
# nameserver 192.168.253.2

nameserver 192.168.253.130     //设置域控制器 IP 地址
nameserver 223.5.5.5
nameserver 127.0.0.1
options edns0

修改 /etc/sysctl.conf

# echo "kern.maxfiles=25600" >> /etc/sysctl.conf
# echo "kern.maxfilesperproc=16384" >> /etc/sysctl.conf
# echo "net.inet.tcp.sendspace=65536" >> /etc/sysctl.conf
# echo "net.inet.tcp.recvspace=65536" >> /etc/sysctl.conf

创建 /etc/krb5.conf

[libdefaults]
	default_realm = SVROS.COM   //设置域名
	dns_lookup_realm = true
	dns_lookup_kdc = true
	ticket_lifetime = 24h
	renew_lifetime = 7d
	forwardable = yes

修改 /etc/nsswitch.conf

# sed -i -e "s/^passwd:.*/passwd: files winbind/" /etc/nsswitch.conf
# sed -i -e "s/^group:.*/group: files winbind/" /etc/nsswitch.conf

创建 /usr/local/etc/smb4.conf

[global]
	workgroup = SVROS
	server string = Samba Server Version %v
	security = ads
	realm = SVROS.COM
	domain master = no
	local master = no
	preferred master = no
	socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072
	use sendfile = true

	idmap config * : backend = tdb
	idmap config * : range = 100000-299999
	idmap config SVROS : backend = rid
	idmap config SVROS : range = 10000-99999
	winbind separator = +
	winbind enum users = yes
	winbind enum groups = yes
	winbind use default domain = yes
	winbind nested groups = yes
	winbind refresh tickets = yes
	template homedir = /home/%D/%U
	template shell = /bin/false

	client use spnego = yes
	client ntlmv2 auth = yes
	encrypt passwords = yes
	restrict anonymous = 2
	log file = /var/log/samba4/log.%m
	max log size = 50

#============================ 自定义共享信息 ==============================

[testshare]
	comment = Test share
	path = /samba/testshare
	read only = no
	force group = "Domain Users"
	directory mode = 0770
	force directory mode = 0770
	create mode = 0660
	force create mode = 0660

上面“testshare”最后两行内容实际使用权限优化(可选)

create mode = 0750
force create mode = 0750

将 samba 加入到域

net ads join --no-dns-updates -U administrator
net ads testjoin
# Should report "Join is OK"
# On your DC, open the DNS MMC and add an "A" entry for your BSD server so clients can find it

使 samba 启动并设置为开机自启动

# echo "samba_server_enable=YES" >> /etc/rc.conf
# echo "winbindd_enable=YES" >> /etc/rc.conf
# service samba_server start

测试 Kerberos

kinit administrator
# Enter domain admin password, it should return to the prompt with no errors
klist
# Credentials cache: FILE:/tmp/krb5cc_0
#    Principal: administrator@SVROS.COM
#
# Issued                Expires               Principal
# Dec  6 10:15:39 2021  Feb  4 20:15:39 2021  krbtgt

测试 Winbind

wbinfo -u
# 应该会返回域用户列表

wbinfo -g
# 应该会返回域用户组列表

getent passwd
# 用户列表末尾应该包含 UID 大于 10000 的域用户

getent group
# 用户组列表末尾应该包含 GID 大于 10000 的域用户组

如果 wbinfo 命令显示报错,请执行命令

# service samba_server restart

创建共享文件夹

# mkdir -p /samba/testshare
# chown "administrator":"domain users" /samba/testshare
# chmod 0770 /samba/testshare

如果只允许属主可读可写,属组只允许读,用以下命令设置:

# chmod 0750 /samba/testshare

如果只允许属主可读可写,属组和其他均不可读写,用以下命令设置:

# chmod -R 0700 /samba/testshare

故障排除与未竞事宜

Samba 日志位于 /var/log/samba4。

上一页16.6 Rsync 同步服务下一页16.8 NFS 服务器

最后更新于1天前