{"id":1291,"date":"2014-10-04T01:21:27","date_gmt":"2014-10-04T07:21:27","guid":{"rendered":"http:\/\/blog.supportpro.com\/?p=1291"},"modified":"2019-08-26T01:44:31","modified_gmt":"2019-08-26T07:44:31","slug":"samba-server-setup-and-cifs-mount","status":"publish","type":"post","link":"https:\/\/www.supportpro.com\/blog\/samba-server-setup-and-cifs-mount\/","title":{"rendered":"Samba Server Setup and CIFS Mount"},"content":{"rendered":"<p>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.<\/p>\n<p>Samba Server uses the following port no. :<br \/>\n137\/tcp<br \/>\n137\/udp<br \/>\n138\/tcp<br \/>\n138\/udp<br \/>\n139\/udp<br \/>\n139\/udp<br \/>\n445\/tcp<br \/>\n445\/udp<\/p>\n<p>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.<!--more--><\/p>\n<p><strong>How to install and configure samba server:<\/strong><\/p>\n<p><strong>Step 1<\/strong>: Install through yum command. cups-libs is for printer.<\/p>\n<p><em>#yum install samba samba-commons cups-libs<\/em><\/p>\n<p><strong>Step 2<\/strong>: create a directory which you would like to share<br \/>\n<em>#mkdir \/shared<\/em><\/p>\n<p><strong>Step 3<\/strong>: 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.<br \/>\n<em>#groupadd staff<\/em><\/p>\n<p><strong>Step 4<\/strong>: Change the group and permission of sharing folder<br \/>\n<em>#chgrp -R staff \/shared\u00a0 chmod -R 777 \/shared<\/em><\/p>\n<p><strong>Step 5<\/strong>: Change the SELinux security context on sharing directory and set the SELinux boolean value for samba.<br \/>\nYou can skip this step if selinux has permissive or disabled status. (use sestatus command to check selinux status)<br \/>\n<em>#chcon -R -t samba_share_t \/shared\/<\/em><br \/>\n<em>#semanage fcontext -a -t samba_share_t \/shared\/<\/em><br \/>\n<em>#setsebool -P samba_enable_home_dirs on<\/em><\/p>\n<p><strong>Step 6<\/strong>: create user and add them in group called staff. And set the samba password for this user.<br \/>\n<em>#useradd test<\/em><br \/>\n<em>#usermod -G staff test<\/em><br \/>\nSet Password, here test123<br \/>\n<em>#smbpasswd -a test<\/em><br \/>\nNew SMB password:<br \/>\nRetype new SMB password:<br \/>\n<em>#tdbsam_open<\/em>: Converting version 0.0 database to version 4.0.<br \/>\n<em>#tdbsam_convert_backup<\/em>: updated \/var\/lib\/samba\/private\/passdb.tdb file.<\/p>\n<p><strong>Step 7<\/strong>: Take backup of \/etc\/samba\/smb.conf file then edit the smb.conf file.<br \/>\n<em>#cd \/etc\/samba\/<\/em><br \/>\n<em>#cp -p smb.conf smb.conf.orig<\/em><br \/>\nAnd add the below given parameters in last line of\u00a0 samba config file \/etc\/samba\/smb.conf file<br \/>\n<em>#vi \/etc\/samba\/smb.conf<\/em><\/p>\n<p>[backup]<br \/>\ncomment = shared-directory<br \/>\npath = \/shared<br \/>\npublic = no<br \/>\nvalid users = test, @staff<br \/>\nwritable = yes<br \/>\nbrowseable = yes<br \/>\ncreate mask = 0777<br \/>\ndirectory mask = 777<br \/>\nforce directory mode = 755<br \/>\nforce group = root<br \/>\nforce create mode = 644<br \/>\nforce user = root<br \/>\ncreate mode = 644<br \/>\ndirectory mode = 775<\/p>\n<p>The name in square braces is the name that we are referring while doing mount from remote server<\/p>\n<p><strong>Step 8<\/strong>: Edit these lines in \/etc\/samba\/smb.conf . To allow network to reach samba server.<\/p>\n<p>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.<br \/>\nIn second line ,192.168.0. is for subnet .Same rule applied to 127. which is for loopback.<\/p>\n<p><em>#vi \/etc\/samba\/smb.conf<\/em><\/p>\n<p>interfaces = lo eth0 eth1 192.168.0.0\/24<br \/>\nhosts allow = xxx.xxx.xxx.xxx<\/p>\n<p>Please test the syntax on the config file using &#8216;<em>testparm \/etc\/samba\/smb.conf&#8217;\u00a0<\/em> after the changes.<\/p>\n<p>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.<\/p>\n<p>workgroup = MYGROUP<\/p>\n<p><strong>Step 9:<\/strong>\u00a0Add services in \/etc\/services files<br \/>\n<em>#vi \/etc\/services<\/em><\/p>\n<p>netbios-ns\u00a0\u00a0\u00a0 137\/tcp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # netbios name service<br \/>\nnetbios-ns\u00a0\u00a0\u00a0 137\/udp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # netbios name service<br \/>\nnetbios-dgm\u00a0\u00a0\u00a0 138\/tcp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # netbios datagram service<br \/>\nnetbios-dgm\u00a0\u00a0\u00a0 138\/udp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # netbios datagram service<br \/>\nnetbios-ssn\u00a0\u00a0\u00a0 139\/udp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # netbios session service<br \/>\nnetbios-ssn\u00a0\u00a0\u00a0 139\/udp\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # netbios session service<\/p>\n<p><strong>Step 10<\/strong>: Add iptables rule in samba server for port no. 137,138.139 and 445.<\/p>\n<p>Edit \/etc\/sysconfig\/iptables file<\/p>\n<p>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.<\/p>\n<p><em>vi \/etc\/sysconfig\/iptables<\/em><\/p>\n<p>Add the below lines\u00a0 to the file \/etc\/sysconfig\/iptables just before COMMIT or open the ports for the IPs<\/p>\n<p>-A INPUT -s 192.168.1.0\/24 -m state \u2013state NEW -p tcp \u2013dport 137 -j ACCEPT<br \/>\n-A INPUT -s 192.168.1.0\/24 -m state \u2013state NEW -p tcp \u2013dport 138 -j ACCEPT<br \/>\n-A INPUT -s 192.168.1.0\/24 -m state \u2013state NEW -p tcp \u2013dport 139 -j ACCEPT<br \/>\n-A INPUT -s 192.168.1.0\/24 -m state \u2013state NEW -p tcp \u2013dport 445 -j ACCEPT<\/p>\n<p>Now save and restart the iptables<\/p>\n<p><strong>Step 11<\/strong>: Now start the smb and nmb services.<\/p>\n<p><em>#\/etc\/init.d\/smb start<\/em><br \/>\n<em>#\/etc\/init.d\/nmb start<\/em><br \/>\n<em>#chkconfig smb on<\/em><br \/>\n<em>#chkconfig nmb on<\/em><\/p>\n<p><strong>Step 12<\/strong>: Now we will test samba from linux<\/p>\n<p><em>#mount -t cifs \/\/samba-server-ipaddress\/shared-directory-name -o username=USERNAME \/mnt\/<\/em><\/p>\n<p>In our Example:<br \/>\n<em>#mount -t cifs \/\/xxx.xxx.xxx.xxx\/shared -p username=test password=test123 \/backup<\/em><br \/>\nFstab entry (\/etc\/fstab)<br \/>\n\/\/<em>xxx.xxx.xxx.xxx<\/em>\/shared \/backup cifs\u00a0 username=test,password=test123,rw 0 0<br \/>\n<em># df -h |grep backup<\/em><br \/>\n\/\/<em>xxx.xxx.xxx.xxx<\/em>\/shared\u00a0 917G\u00a0\u00a0 17G\u00a0 854G\u00a0\u00a0 2% \/backup<\/p>\n<p>Windows User:<\/p>\n<p>Open the Run and type \\\\ip-address-of-samba-server\\shared-Direcory-name<\/p>\n<p>eg :\u00a0 \\\\<em>xxx.xxx.xxx.xxx<\/em>\\shared<\/p>\n<p>Give username and password. here the suername is \u201ctest\u201d and the password is \u201ctest123\u2033<\/p>\n<p>If you require help, <a href=\"https:\/\/www.supportpro.com\/requestquote.php\">contact SupportPRO Server Admin<\/a><\/p>\n<p style=\"text-align: center;\"><!--HubSpot Call-to-Action Code --><span id=\"hs-cta-wrapper-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-wrapper\"><span id=\"hs-cta-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-node hs-cta-9d590242-d641-4383-94b4-8cfd62f0af6b\"><!-- [if lte IE 8]><\/p>\n\n\n\n\n\n<div id=\"hs-cta-ie-element\"><\/div>\n\n\n<![endif]--><a href=\"https:\/\/www.supportpro.com\/requestquote.php\"><img decoding=\"async\" id=\"hs-cta-img-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-img\" style=\"border-width: 0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/2725694\/9d590242-d641-4383-94b4-8cfd62f0af6b.png\" alt=\"Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value\" \/><\/a><\/span><script charset=\"utf-8\" src=\"https:\/\/js.hscta.net\/cta\/current.js\"><\/script><script type=\"text\/javascript\"> hbspt.cta.load(2725694, '9d590242-d641-4383-94b4-8cfd62f0af6b', {}); <\/script><\/span><!-- end HubSpot Call-to-Action Code --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[5,6,1],"tags":[],"class_list":["post-1291","post","type-post","status-publish","format-standard","hentry","category-general-topics","category-linux-basics","category-miscellaneous"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/comments?post=1291"}],"version-history":[{"count":7,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1291\/revisions"}],"predecessor-version":[{"id":4134,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1291\/revisions\/4134"}],"wp:attachment":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media?parent=1291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/categories?post=1291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/tags?post=1291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}