Samba is a free and open-source implementation of SMB/CIFS.
Samba provides file and print services over network which can be accessed by Windows, Unix and MacOS X clients.
Alternatives are NFS and SSHFS.
The version of Samba included in the OpenWrt feeds is version 4,
It is strongly recommended that you use LuCI to establish the initial configuration and then edit the template file (/etc/samba/smb.conf.template) via LuCI Edit Template tab or from the shell as needed.
On devices with 32Mbyte of RAM you will most likely run into memory issues, adding swap might help but devices with at least 128Mbyte is recommended and a 128-256Mbyte swap if possible.
Presuming you want to connect a USB hard disk to the device and then access its contents over the cifs protocol, you need to mount that drive first:
uci -q delete firewall.samba_nsds uci set firewall.samba_nsds="rule" uci set firewall.samba_nsds.name="Allow-Samba/NS/DS" uci set firewall.samba_nsds.src="lan" uci set firewall.samba_nsds.dest_port="137-138" uci set firewall.samba_nsds.proto="udp" uci set firewall.samba_nsds.target="ACCEPT" uci -q delete firewall.samba_ss uci set firewall.samba_ss="rule" uci set firewall.samba_ss.name="Allow-Samba/SS" uci set firewall.samba_ss.src="lan" uci set firewall.samba_ss.dest_port="139" uci set firewall.samba_ss.proto="tcp" uci set firewall.samba_ss.target="ACCEPT" uci -q delete firewall.samba_smb uci set firewall.samba_smb="rule" uci set firewall.samba_smb.name="Allow-Samba/SMB" uci set firewall.samba_smb.src="lan" uci set firewall.samba_smb.dest_port="445" uci set firewall.samba_smb.proto="tcp" uci set firewall.samba_smb.target="ACCEPT" uci commit firewall /etc/init.d/firewall restart
Windows and most GNU/Linux distribution come with pre-installed support for this. So does MacOS X since version 10.2. In case your distribution is missing support, you need to install the client software. ArchLinux offers a Wikipage: https://wiki.archlinux.org/index.php/Samba#Configuration.
After modifying any of the config files, restart the Samba server so that your changes take effect:
Info: When Samba is restarted this way, the file
/etc/samba/smb.conf is (re)created from to the uci configuration file and
Create Samba users by adding them to /etc/passwd and /etc/group, then using
smbpasswd to set passwords and add to Samba.
Set up shared directories permissions according to your needs using
Any unknown usernames used for authentication against Samba are mapped to a guest login silently by default.
Samba is the only built in way to share resources between computers running Microsoft Windows.
Even in a professional environment.
Thus it can be very complicated to configure! It is also not the protocol of choice to accomplish that task in a Linux/Mac environment.
So, if for whatever reasons above configuration does not give you desired access to your configured shares, you can of course circumvent the uci system and hack the original Samba configuration files instead or in addition.
There may be entries which do not have a counterpart in UCI (yet) and thus can only be configured that way.
Just bear in mind, that the uci config will overwrite the values configured with it (but not the whole configuration) at every boot up! If you want configure Samba directly with
/etc/samba/smb.conf instead of
/etc/config/samba, it is possible to make changes to the smb.conf survive a reboot using the procedure below.
First, prevent OpenWrt from starting Samba at boot time, thus overwriting
/etc/samba/smb.conf with the settings in the uci file
Then add the following lines to /etc/rc.local to allow smbd and nmbd to start at boot time, using
/etc/samba/smb.conf as the configuration file
smbd -D nmbd -D
Now edit your
/etc/samba/smb.conf all you like without worrying they will be lost the next time you reboot!
Same procedure as with most OpenWrt packages: The first command will create a symlink
/etc/rc.d/S60samba, the second will only start samba right now.
/etc/init.d/samba enable /etc/init.d/samba start
ps auxshould show
nmbd -Dup and running
When using a Windows 7 client, you may have trouble accessing the network shares when Samba is set to user security, especially when using the “Map Network Drive” option from within Explorer. To circumvent this problem, try logging, choose to login using different credentials and type your username all in caps.
If this still doesn't work, on the Windows 7 client(s) start a command shell (Win+R, type cmd and press enter), then issue the following command:
net use R: \\openwrt\<share> /USER:<USERNAME> <password>
If you changed your router hostname, openwrt must be changed accordingly.
Some hints in advance:
share, restart the daemons and try accessing it directly: In windows explorer type
\\router_ipin the address bar.
smb://router_ip/into the address bar.
Instead of looking up the whole configuration step by step, you maybe want to have a look at Samba.org: Example Network Configurations. Chapter 1: No-Frills Samba Servers. Notice that you can already achieve a great deal of security by neatly setting up the Firewall Documentation
If Samba does not start, try adding your router's name and ip in /etc/hosts. (see also http://forum.openwrt.org/viewtopic.php?id=5401)
When Samba is configured, the shares are set browse-able, but they still don't appear when browsing the network, then it may be that
local master = yes is missing from
Also check if
preferred master = yes is in
If you cannot write to the share, Samba may not have the proper permissions to write to the shared folder.
Some have reported success by modifying the permissions and owner of the folder:
chmod -R 777 /mnt/sda1 chown -R nobody /mnt/sda1
If you are sharing a drive mounted wish fstab, you may need to modify /etc/config/fstab to include 'umask=000' in the options section.
config 'mount' option 'options' 'rw,umask=000' option 'enabled_fsck' '0' option 'enabled' '1' option 'device' '/dev/scsi/host0/bus0/target0/lun0/part1' option 'target' '/mnt/usbdisk' option 'fstype' 'vfat'
More info here: https://forum.openwrt.org/viewtopic.php?id=26625
If you need to read/write files and folders with accented characters.
sed -i -e "/unix charset/s/ISO-8859-1/UTF-8/" /etc/samba/smb.conf.template
Since netfilter tracks every connection, disable conntrack for Samba connections if you use NAT.
uci -q delete firewall.samba_nsds_nt uci set firewall.samba_nsds_nt="rule" uci set firewall.samba_nsds_nt.name="NoTrack-Samba/NS/DS" uci set firewall.samba_nsds_nt.src="lan" uci set firewall.samba_nsds_nt.dest="lan" uci set firewall.samba_nsds_nt.dest_port="137-138" uci set firewall.samba_nsds_nt.proto="udp" uci set firewall.samba_nsds_nt.target="NOTRACK" uci -q delete firewall.samba_ss_nt uci set firewall.samba_ss_nt="rule" uci set firewall.samba_ss_nt.name="NoTrack-Samba/SS" uci set firewall.samba_ss_nt.src="lan" uci set firewall.samba_ss_nt.dest="lan" uci set firewall.samba_ss_nt.dest_port="139" uci set firewall.samba_ss_nt.proto="tcp" uci set firewall.samba_ss_nt.target="NOTRACK" uci -q delete firewall.samba_smb_nt uci set firewall.samba_smb_nt="rule" uci set firewall.samba_smb_nt.name="NoTrack-Samba/SMB" uci set firewall.samba_smb_nt.src="lan" uci set firewall.samba_smb_nt.dest="lan" uci set firewall.samba_smb_nt.dest_port="445" uci set firewall.samba_smb_nt.proto="tcp" uci set firewall.samba_smb_nt.target="NOTRACK" uci commit firewall /etc/init.d/firewall restart
As the latest version of Mac OS X (Yosemite) has problems discovering SMB network shares broadcasted by each client over the LAN, you can set up a WINS server on your router which will help them out.
A WINS server is a centralized name server for SMB network shares. The objective is to make the router the master browser which means it will discover SMB network shares then make them available over the WINS service. Macs will connect to the WINS service to receive the list of network shares, hopefully with more success than discovering network shares themselves.
We will edit the UCI template (
/etc/samba/smb.conf.template) instead of directly changing
/etc/samba/smb.conf so as to maintain compatibility with UCI and LuCI.
Log into LuCI, go to Services > Network Shares, go to the Edit Template tab, and add or change the following entries in the “[global]” section in the template.
[global] domain master = yes local master = yes name resolve order = wins lmhosts hosts bcast os level = 99 preferred master = yes wins support = yes
Finally Save & Apply the changes.
You can also configure dnsmasq to broadcast the WINS server address via DHCP:
uci add_list dhcp.lan.dhcp_option="44,$(uci get network.lan.ipaddr)" uci commit dhcp /etc/init.d/dnsmasq restart
SMB network shares should appear in Network home a few minutes after rebooting the Mac.