Samba is a free software re-implementation of the SMB/CIFS networking protocol. We need to set up and configure samba server where the drive to share or mount is located.
Samba Server uses the following port no. :
137/tcp
137/udp
138/tcp
138/udp
139/udp
139/udp
445/tcp
445/udp
Daemon name: smb and nmb Samba services are implemented as two daemons: smbd, which provides the file and printer sharing services, and nmbd, which provides the NetBIOS-to-IP-address name service. NetBIOS over TCP/IP requires some method for mapping NetBIOS computer names to the IP addresses of a TCP/IP network.
How to install and configure samba server:
Step 1: Install through yum command. cups-libs is for printer.
#yum install samba samba-commons cups-libs
Step 2: create a directory which you would like to share
#mkdir /shared
Step 3: Add a new group or you can use an existing group to provide access on a shared directory, Here I am adding a new group called staff.
#groupadd staff
Step 4: Change the group and permission of sharing folder
#chgrp -R staff /shared chmod -R 777 /shared
Step 5: Change the SELinux security context on sharing directory and set the SELinux boolean value for samba.
You can skip this step if selinux has permissive or disabled status. (use sestatus command to check selinux status)
#chcon -R -t samba_share_t /shared/
#semanage fcontext -a -t samba_share_t /shared/
#setsebool -P samba_enable_home_dirs on
Step 6: create user and add them in group called staff. And set the samba password for this user.
#useradd test
#usermod -G staff test
Set Password, here test123
#smbpasswd -a test
New SMB password:
Retype new SMB password:
#tdbsam_open: Converting version 0.0 database to version 4.0.
#tdbsam_convert_backup: updated /var/lib/samba/private/passdb.tdb file.
Step 7: Take backup of /etc/samba/smb.conf file then edit the smb.conf file.
#cd /etc/samba/
#cp -p smb.conf smb.conf.orig
And add the below given parameters in last line of samba config file /etc/samba/smb.conf file
#vi /etc/samba/smb.conf
[backup]
comment = shared-directory
path = /shared
public = no
valid users = test, @staff
writable = yes
browseable = yes
create mask = 0777
directory mask = 777
force directory mode = 755
force group = root
force create mode = 644
force user = root
create mode = 644
directory mode = 775
The name in square braces is the name that we are referring while doing mount from remote server
Step 8: Edit these lines in /etc/samba/smb.conf . To allow network to reach samba server.
Change the value of 192.168.0.0/24 with your subnet. And change the ethernet value which is in use by your system and which you want to allow for traffic.
In second line ,192.168.0. is for subnet .Same rule applied to 127. which is for loopback.
#vi /etc/samba/smb.conf
interfaces = lo eth0 eth1 192.168.0.0/24
hosts allow = xxx.xxx.xxx.xxx
Please test the syntax on the config file using ‘testparm /etc/samba/smb.conf’ after the changes.
Note: Mainly for Windows users, if your all PC in your network are using different WORKGROUP name edit the given below line in smb.conf with your workgroup name. Windows system by default uses the WORKGROUP as WORKGROUP. Try first without changing the WORKGROUP name, if required do the change.
workgroup = MYGROUP
Step 9: Add services in /etc/services files
#vi /etc/services
netbios-ns 137/tcp # netbios name service
netbios-ns 137/udp # netbios name service
netbios-dgm 138/tcp # netbios datagram service
netbios-dgm 138/udp # netbios datagram service
netbios-ssn 139/udp # netbios session service
netbios-ssn 139/udp # netbios session service
Step 10: Add iptables rule in samba server for port no. 137,138.139 and 445.
Edit /etc/sysconfig/iptables file
Note: If in your network iptables service is stopped or there is no rule set up.Kindly skip this step. Change the 192.168.1.0/24 value with you network subnet.
vi /etc/sysconfig/iptables
Add the below lines to the file /etc/sysconfig/iptables just before COMMIT or open the ports for the IPs
-A INPUT -s 192.168.1.0/24 -m state –state NEW -p tcp –dport 137 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m state –state NEW -p tcp –dport 138 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m state –state NEW -p tcp –dport 139 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m state –state NEW -p tcp –dport 445 -j ACCEPT
Now save and restart the iptables
Step 11: Now start the smb and nmb services.
#/etc/init.d/smb start
#/etc/init.d/nmb start
#chkconfig smb on
#chkconfig nmb on
Step 12: Now we will test samba from linux
#mount -t cifs //samba-server-ipaddress/shared-directory-name -o username=USERNAME /mnt/
In our Example:
#mount -t cifs //xxx.xxx.xxx.xxx/shared -p username=test password=test123 /backup
Fstab entry (/etc/fstab)
//xxx.xxx.xxx.xxx/shared /backup cifs username=test,password=test123,rw 0 0
# df -h |grep backup
//xxx.xxx.xxx.xxx/shared 917G 17G 854G 2% /backup
Windows User:
Open the Run and type \\ip-address-of-samba-server\shared-Direcory-name
eg : \\xxx.xxx.xxx.xxx\shared
Give username and password. here the suername is “test” and the password is “test123″
If you require help, contact SupportPRO Server Admin