Saturday, September 13, 2008

Samba tutorial - Part 4

Running The Daemons

The two SMB daemons are /usr/sbin/smbd and /usr/sbin/nmbd. Under most Linux distributions, these are started, stoped and restarted via the startup script located in /etc/rc.d/init.d/smb and symlinked to the appropriate runlevels.

If you choose not to use the standard startup script, you can run the Samba daemons from inetd or as stand-alone processes. Samba will respond slightly faster as a standalone daemon than running from inetd.

In either case, you should check the file /etc/services for lines that look like this:


netbios-ns      137/tcp         nbns
netbios-ns 137/udp nbns
netbios-dgm 138/tcp nbdgm
netbios-dgm 138/udp nbdgm
netbios-ssn 139/tcp nbssn

Make sure they are all uncommented. Depending on your distribution, you may even need to add them. Samba will not be able to bind to the appropriate ports unless /etc/services has these entries.

To run the daemons from inetd, place the following lines in the inetd configuration file, /etc/inetd.conf:


    # SAMBA NetBIOS services (for PC file and print sharing)
netbios-ssn stream tcp nowait root /usr/sbin/smbd smbd
netbios-ns dgram udp wait root /usr/sbin/nmbd nmbd

Then restart the inetd daemon by running the command:


    kill -HUP `cat /var/run/inetd.pid`

To run the daemons from the system startup scripts, put the following script in file called /etc/rc.d/init.d/smb (for most distributions) and symbolically link it to the files specified in the comments:


    #!/bin/sh

#
# /etc/rc.d/init.d/smb - starts and stops SMB services.
#
# The following files should be synbolic links to this file:
# symlinks: /etc/rc.d/rc1.d/K35smb (Kills SMB services on shutdown)
# /etc/rc.d/rc3.d/S91smb (Starts SMB services in multiuser mode)
# /etc/rc.d/rc6.d/K35smb (Kills SMB services on reboot)
#

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

# See how we were called.
case "$1" in
start)
echo -n "Starting SMB services: "
daemon smbd -D
daemon nmbd -D
echo
touch /var/lock/subsys/smb
;;
stop)
echo -n "Shutting down SMB services: "
killproc smbd
killproc nmbd
rm -f /var/lock/subsys/smb
echo ""
;;
*)
echo "Usage: smb {start|stop}"
exit 1
esac

If when starting Samba you get an error that says something about the daemon failing to bind to port 139, then you probably have another Samba process already running that hasn't yet shut down. Check a process list (with 'ps auxww | grep mbd') to determine if another Samba service is running.

Samba tutorial - Part 3

Installation

First, in order to use Samba your machines must be on a single ethernet LAN segment using the TCP/IP protocol. Samba will not work using other network protocols. This is generally easy since Linux and Windows 95/98/NT ship with TCP/IP support. However, if you are using Windows 3.X machines TCP/IP support will need to be added. One of the most common questions that I get asked is why Samba "isn't working" when Windows machines are not using TCP/IP.

In order to setup Windows 95/98 to use TCP/IP, select Control Panel | Network, then add and configure Microsoft TCP/IP. Under Windows NT, select Control Panel | Network | Protocols.

To get the latest source version of Samba, go to this URL and pick the closest mirror site to you: ftp://ftp.samba.org/.

In most cases, though, your Linux distribution will already come with an installable package containing a recent version of Samba.

The following two daemons are required for the Samba package. They are typically installed in /usr/sbin and run either on boot from the systems startup scripts or from inetd. Example scripts are shown in Running the Daemons.


        smbd (The SMB daemon)
nmbd (Provides NetBIOS nameserver support to clients)

Please note that the name service provided by the nmbd daemon is different from the name service provided by the Domain Name Service (DNS). NetBIOS name service is a 'Windows-style' name service used for SMB. In other words, having DNS name service tells you nothing about the state of the ability for Samba to resolve host names.

Typically, the following Samba binaries are installed in /usr/bin or /usr/local/samba/bin, although the location is optional.


        smbclient       (An SMB client for UNIX machines)
smbprint (A script to print to a printer on an SMB host)
smbprint.sysv (As above, but for SVR4 UNIX machines)
smbstatus (Lists the cuurent SMB connections for the local host)
smbrun (A 'glue' script to facilitate runnning applciations
on SMB hosts)

The binaries for smbfs file system support are discussed later in this document.

Additionally, a script called 'print' is included with this HOWTO, which serves as a useful front end to the smbprint script.

The Samba package is simple to install. Simply retrieve the source from the location mentioned above, and read the file README in the distribution. There is also a file called docs/INSTALL.txt in the distribution that provides a simple step-by-step set of instructions.

Following installation, place the daemons in /usr/sbin and the binaries in /usr/bin. Install the man pages in /usr/local/man.

When you made the Samba package, you would have specified in the Makefile the location for the configuration file, smb.conf. This is generally in /etc, but you can put it anywhere you like. For these directions, we will presume that you specified the location of the configuration file as /etc/smb.conf, the log file location as log file = /var/log/samba-log.%m and the lock directory as lock directory = /var/lock/samba.

Install the configuration file, smb.conf. Go to the directory where Samba was built. Look in the subdirectory examples/simple and read the file README. Copy the file smb.conf found in that directory to /etc. BE CAREFUL! If you have a Linux distribution that already has Samba installed, you may already have a Samba configuration file in /etc. You should probably start with that one.

If you don't want to have your configuration file in /etc, put it wherever you want to, then put a symlink in /etc:


        ln -s /path/to/smb.conf /etc/smb.conf

Samba tutorial - Part 2

This HOWTO attempts to explain how to configure basic SMB file and print services on a Linux machine. Samba is a very complex and complete package. There would be no point in attempting to duplicate all of the documentation for Samba here.

For further information, please see the following documents:

  • The Samba documentation, available as part of the Samba distribution. The distribution is available at: ftp://ftp.samba.org/
  • The Linux Printing HOWTO.
  • Protocol Standard For A NetBIOS Service On A TCP/UDP Transport.
    RFC 1001

    > RFC 1001 - Concepts and Methods.

    RFC 1002

    > RFC 1002 - Detailed Specifications.

Your Ad Here