智能路由器-OpenWRT 系列五 (NAS-SMB家庭共享)
NAS是我覺得家里必不可少的一臺設備,NAS 全稱 Network Attached Storage,即網(wǎng)絡附加存儲服務器,它通過自身的操作系統(tǒng)和 SMB/NFS/CIFS/FTP 等多種通信協(xié)議來給各種設備和平臺提供數(shù)據(jù)的存儲、訪問和管理的服務,詳細可見百度、維基。而家用 NAS 廠家都給我們提供了友善的圖形化 Web 操作界面,定制化程度很高,可以很方便的進行服務部署、端口設置、權限管理等操作。主要品牌有群暉 Synology 和威聯(lián)通 QNAP 。
OpenWRT作為最靈活和強大的路由器操作系統(tǒng),基于它搭建簡單易用的家庭網(wǎng)絡共享,可以滿足一般的日常使用。
下面我們看下如何使用OpenWRT搭建SMB家庭共享,實現(xiàn)基礎的共享功能。
?
Samba是在Linux和UNIX系統(tǒng)上實現(xiàn)SMB協(xié)議的一個免費軟件,由服務器及客戶端程序構成。SMB(Server Messages Block,信息服務塊)是一種在局域網(wǎng)上共享文件和打印機的一種通信協(xié)議,它為局域網(wǎng)內的不同計算機之間提供文件及打印機等資源的共享服務。SMB協(xié)議是客戶機/服務器型協(xié)議,客戶機通過該協(xié)議可以訪問服務器上的共享文件系統(tǒng)、打印機及其他資源。通過設置“NetBIOS over TCP/IP”使得Samba不但能與局域網(wǎng)絡主機分享資源,還能與全世界的電腦分享資源。?
OpenWRT掛載完U盤/移動硬盤后,可以通過Samba實現(xiàn)局域網(wǎng)共享。
每次ssh登陸OpenWRT安裝新軟件時,都必須更新opkg
opkg update前提
2. 配置防火墻策略,保證137 、138 、139、445 端口是打開的。
vi /etc/config/firewall增加以下內容config 'rule'option 'src' 'lan'option 'proto' 'udp'option 'dest_port' '137-138'option 'target' 'ACCEPT'config 'rule'option 'src' 'lan'option 'proto' 'tcp'option 'dest_port' '139'option 'target' 'ACCEPT'config 'rule'option 'src' 'lan'option 'proto' 'tcp'option 'dest_port' '445'option 'target' 'ACCEPT'保存并退出安裝SMB服務
Samba是在Linux和UNIX系統(tǒng)上實現(xiàn)SMB協(xié)議的一個免費軟件,由服務器及客戶端程序構成。Samba支持DOS、Windows、OS/2,Linux以及其他平臺訪問。
opkg update opkg install samba36-server /etc/init.d/samba enable /etc/init.d/samba start配置SMB
Samba的配置文件為/etc/samba/smb.conf,但是我們配置時不應該直接編輯/etc/samba/smb.conf,而應該編輯/etc/samba/smb.conf.template文件。 因為每次samba重啟時,/ 配置為開機啟動etc/samba/smb.conf都會從/etc/samba/smb.conf.template重新創(chuàng)建,導致我們的配置丟失。
下面開始簡單的配置:
vi /etc/samba/smb.conf.template
例如要添加一個名稱為smb的共享,共享路徑為/smb2,允許匿名用戶讀寫操作,在/etc/samba/smb.conf.template 配置文件最下方增加如下信息:
[smb] path = /smb2 read only = no guest ok = yes create mask = 0750 directory mask = 0750重新啟動samba
/etc/init.d/samba restart訪問
完成如上配置,一個簡單的smb共享就完成了。
Windows 輸入 \192.168.1.1\smb Mac 系統(tǒng)輸入 smb://192.168.1.1/smb 既可以訪問到我們的smb共享,且不需要輸入密碼
如果在網(wǎng)絡上搜索‘ OpenWRT Samba ’,會發(fā)現(xiàn)很多文章的配置是不清晰的。一般會開始就上來讓你 修改配置文件/etc/samba/smb.conf,注釋掉 invalid users = root, 這其實是完全沒有必要的。 只有需要賬號密碼訪問時才需要這些操作。
看下如何正確的使用賬號密碼訪問smb共享
取消匿名訪問
如果想為我們的smb共享增加用戶名、密碼訪問功能。則需要如下設置
vi /etc/samba/smb.conf.template
將[global]中的invalid users = root注掉,guest ok = yes注釋掉,像下面的樣子:
[global] netbios name = OpenWrt display charset = UTF-8 interfaces = 127.0.0.1/8 lo 192.168.1.1/24 br-lan server string = OpenWrt unix charset = UTF-8 workgroup = WORKGROUP browseable = yes deadtime = 30 domain master = yes encrypt passwords = true enable core files = no guest account = nobody #guest ok = yes #invalid users = root local master = yes load printers = no map to guest = Bad User max protocol = SMB2 min receivefile size = 16384 null passwords = yes obey pam restrictions = yes os level = 20 passdb backend = smbpasswd preferred master = yes printable = no security = user smb encrypt = disabled smb passwd file = /etc/samba/smbpasswd socket options = TCP_NODELAY IPTOS_LOWDELAYsyslog = 2 use sendfile = yes writeable = yes同時將剛剛的smb共享部分調整如下:
[smb] path = /smb2 read only = no #guest ok = yes #注釋掉guest匿名訪問 valid users = root #允許root用戶訪問 create mask = 0750 directory mask = 0750重啟
/etc/init.d/samba restart這時我們發(fā)現(xiàn)//192.168.1.1/smb 無法直接訪問了,需要輸入用戶名密碼。 但是我們輸入用戶root 和它的密碼時仍然無法登陸。 那是因為需要單獨為samba設置用戶密碼。
smbpasswd -a root New SMB password: Retype SMB password: /etc/init.d/samba restart設置好密碼后 重啟 訪問 輸入密碼,是不是好了。 如果不想使用root用戶,可以參考如下步驟,創(chuàng)建新用戶,并為新用戶創(chuàng)建smbpasswd
User level accessAt user level access a username and password are needed to access the share.Steps:1. Add user to systemTo access a samba share with user level access there must be a user added to the system. Edit /etc/passwd and add a line for the new user. Choose a user id (the first number in the line) of 1000 or higher that does not exist yet. Set the group identification number (the second number) to the same number as the user nobody. Copy the rest.root:!:0:0:root:/root:/bin/ash nobody:*:65534:65534:nobody:/var:/bin/false daemon:*:65534:65534:daemon:/var:/bin/false newuser:*:1000:65534:newuser:/var:/bin/false Note: keep in mind that the user(s) and group(s) utilized by Samba need to have the proper permissions for their shares, i.e. they need write access in order to write via smb.2. Add samba password to usersmbpasswd -a newuser3. Change samba config to accept users with null passwordsEdit /etc/samba/smb.conf.template and add null passwords = yes:[global]netbios name = |NAME| workgroup = |WORKGROUP|server string = |DESCRIPTION|syslog = 10encrypt passwords = truepassdb backend = smbpasswdobey pam restrictions = yessocket options = TCP_NODELAYunix charset = ISO-8859-1local master = yespreferred master = yesos level = 20security = usernull passwords = yesguest account = nobodyinvalid users = rootsmb passwd file = /etc/samba/smbpasswd4. Add a shareThen add a share to /etc/config/samba. Make shure that guest ok is set to noconfig 'samba'option 'name' 'openwrt'option 'workgroup' 'WORKGROUP'option 'description' 'openwrt'option 'homes' '1'config 'sambashare'option 'read_only' 'no'option 'create_mask' '0700'option 'dir_mask' '0700'option 'name' 'name-of-share'option 'path' '/path/of/share'option 'guest_ok' 'no' This share should now be accessible by \\ip-adress-openwrt\name-of-share (windows, correct username and password are needed).參考
Samba How To
Samba (smb)
?
本站文章除注明轉載外,均為本站原創(chuàng)或編譯。歡迎任何形式的轉載,但請務必注明出處。 轉載請注明:文章轉載自 「 微桔智居?? http://wizju.com?」 本文標題:?智能路由器-OpenWRT 系列五 (NAS-SMB家庭共享) 本文地址:http://wizju.com/post/142/?
轉載于:https://www.cnblogs.com/wizju/p/6923625.html
總結
以上是生活随笔為你收集整理的智能路由器-OpenWRT 系列五 (NAS-SMB家庭共享)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OAuth2.0学习(1-1)OAuth
- 下一篇: 为 Nginx 创建 windows 服