CentOS – Building A Samba Server

CentOS – Building A Samba Server

Introduction

This article provides the steps to build a CentOS 5.5 Samba server to provide CIFS/SMB shares on a network.

The CentOS server built for this article was a base installation with the Firewall and SELinux left Enabled.

Pre-Requisites

  • A Basic installation of CentOS 5.5

Installing Samba

Installing the Samba Server software on to CentOS server is a straight forward task using yum.

To install the Samba Server software perform the following steps :-

  • At the command prompt execute the following command :-

yum install samba.x86_64

  • If necessary additional dependency packages will be downloaded

Configuring The Smb.Conf File

The next step is to configure the smb.conf file on the server under/etc/samba folder. A very basic smb.conf file will be created from scratch to share out the folder /Software on the server for the purposes of this article

To configure the smb.conf file perform the following steps :-

  • At the command change directory to /etc/samba by executing the following command :-

cd /etc/samba

  • Next move the existing smb.conf file to smb.conf.old by
  • executing the following command :-

mv smb.conf smb.conf.old

  • Edit a new file named smb.conf in your preferred editor and add the following lines :-

[global]

        workgroup = lost-it.local

        server string = nobby

        netbios name = nobby

        security = shared

        username = /etc/samba/smbusers

        guest account = nobody

[software]

        path = /Software

        browsable = yes

        guest ok = yes

        writeable = yes

        public = yes

  • Save and Exit the file

Starting & Configuring The Samba Service To Start Automatically

The last  step is to start the Samba Service and configure it to start automatically

To start the Samba Server perform the following steps :-

  • At the command execute the following command :-

service smb start

  • To configure the Samba Service to start automatically execute the following command :-

chkconfig smb on

Configuring Iptables To Allow Access

If you have the Firewall running on the server you need to allow access to the Samba Ports.

To allow access to Samba from remote machines perform the following steps :-

  • At the command change directory to /etc/sysconfig by executing the following command :-

cd /etc/sysconfig

  • Edit a the file named iptables in your preferred editor and add the following lines at the end of the file but BEFORE the line COMMIT :-

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 445 -j ACCEPT

-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 445 -j ACCEPT

-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 137 -j ACCEPT

-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 138 -j ACCEPT

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 139 -j ACCEPT

  • Save and Exit the file
  • Reload the Firewall by executing the following command :-

service iptables reload

Configuring Samba With SELinux

If you have the SELinux running on the server you need to allow access to the filesystem.

To allow access to the filesystem from remote machines perform the following steps :-

  • At the command execute the following command :-

semanage fcontext -a -t samba_share_t ‘/Software(/.*)?’

restorecon -R /Software