Linux:Powerful Server Administration
上QQ阅读APP看书,第一时间看更新

Troubleshooting the Samba server

In this recipe, we will look at the various tools available for troubleshooting Samba shares.

How to do it…

Samba troubleshooting can be separated in to three parts: network connectivity, Samba process issues, and Samba configuration issues. We will go through each of them step by step. As a first step for troubleshooting, let's start with network testing.

Checking network connectivity

Follow these steps to check network connectivity:

  1. Send ping requests to the Samba server to check network connectivity:
    $ ping samba-server-ip
    
  2. Check name resolution. Ping the Samba server by its name. Windows uses netbios for name resolution:
    $ ping samba-server-name
    
  3. Check the Samba configuration for network restrictions. Temporarily open Samba to all hosts.
  4. Use tcpdump to check Samba network communication. Start tcpdump as follows and let it run for some time while accessing the Samba server from clients. All packets will be logged in a file named tcpdump in the current directory:
    $ sudo tcpdump -p -s 0 -w tcpdumps port 445 or port 139
    
  5. If you know the client IP address, you can filter tcpdumps with the following command:
    $ sudo tcpdump -s 0 -w tcpdumps host client_IP
    
  6. Connect to the Samba process with telnet:
    $ echo "hello" | telnet localhost 139
    
  7. Check whether your Samba server uses a firewall. If so, check the allowed ports on your firewall. If the firewall is on, make sure you have allowed the Samba ports as follows:
  8. Try connecting to FTP or a similar TCP service on the Samba server. This may identify the problems with the TCP stack.
  9. Use nmblookup to test netbios name resolution for Windows systems.
Checking the Samba service

Follow these steps to check Samba service:

  1. Check whether the Samba service has started properly:
    $ sudo service samba status
    
  2. Use netstat to check the Samba daemon is listening on the network:
    $ sudo netstat -plutn
    
  3. Use ps to check the Samba processes. Look for the process name, smbd, in the output of the following command:
    $ ps aux
    
  4. Use strace to view the Samba process logs. This will list all filesystem activities by smbd process:
    $ strace smbd
    
Checking Samba logs

Follow these steps to check Samba logs:

  1. Check Samba log files for any warning or errors.
  2. Increase the log level to get more debugging information:
    [global]
    log level = 3
  3. Enable logging for a specific client with client-specific configuration. First, set the following options under smb.conf to enable client-specific configuration:
    [global]
        log level = 0
        log file = /var/log/samba/log.%m
        include = /etc/samba/smb.conf.%m
  4. Now create a new configuration file for a specific client:
    $ sudo vi /etc/samba/smb.conf.client1
    [global]
    log level = 3
  5. Similarly, you can create separate logs for each Samba user:
    [global]
        log level = 0
        log file = /var/log/samba/log.%u
        include = /etc/samba/smb.conf.%u
Checking Samba configuration

Follow these steps to check Samba configuration:

  1. Check the registered users and accounts in the Samba server user database with the pdbedit command:
    $ sudo pdbedit -L
    
  2. Check the shares with the smbtree command:
  3. Use the testparm command to find any errors in the Samba configuration:
    $ testparm
    
  4. Check for allowed users and group names. Make sure that group names start with the @ symbol.
  5. Back up your configuration files and then use minimal configuration to test Samba:
    [global]
        workgroup = WORKGROUP
        security = user
        browsable = yes
    [temp]
        path = /tmp
        public = yes

    Note

    Publicly writable directories are not good for server security. Remove the preceding configuration as soon as testing is finished.

  6. Test your configuration with smbcclient. It should list all Samba shares:
    $ smbclient -L localhost -U%
    

See also