Setting up Samba as an Active Directory Domain Controller

From SambaWiki


This document explains how to setup Samba (4.0+) as a simple Domain Controller that is compatible with Microsoft's Active Directory, for use particularly by Microsoft Windows clients that are joined to the Active Directory domain, for services such as Domain Logon. We refer to this capability as being an AD DC for short.

If you are upgrading an existing AD DC, please consult your distribution upgrade procedure or refer to the upgrading a source version HowTo.


Samba is developing rapidly. This HowTo is frequently updated to reflect the latest changes. Please see the Samba Release Planning for 4.0 and later for more specifics.

Please review the release notes for the version you have installed. It may contain important information, not yet reflected in this HowTo.

Installing Samba

Different ways to install

You have a few options to install Samba:

  • Install from your distribution package manager.


Take care when running Samba commands, if you also have a previous version of Samba installed. To avoid inadvertently running the wrong version, you should consider putting the /usr/local/samba/bin/ and /usr/local/samba/sbin/ directories in the beginning of your $PATH variable!

You can see what version of Samba, if any, is in your PATH variable by running:

# samba -V

Server information

For the rest of this HowTo, we will be using the following configuration/settings for our example AD DC:

Installation Directory: /usr/local/samba/
Server Hostname:        DC1
DNS Domain Name: (This will also be your realm)
NT4 Domain Name:        samdom
IP Address:   
Server Role:            DC

Provisioning Samba (Setting up a new domain)

The provisioning creates a basic database, and is used when you are configuring your first Samba DC in its own domain. If you instead want to setup your Samba server as an additional domain controller in an existing domain, then please see the Joining a Windows Domain Controller as an additional DC in a Domain HowTo.

The provision step must be run as a user with permission to write to the install directory. Otherwise you're getting permission denied errors.

To provision a new domain, run:

# /usr/local/samba/bin/samba-tool domain provision --use-rfc2307 --interactive

This will run the provision tool interactively. Because some settings can't be set interactively, it's recommended to run samba-tool domain provision --help and have a look at the additional possibilities.

The --use-rfc2307 option enables your Samba AD automatically to store posix attributes. It also creates NIS information in the AD, that allows you to administrate UIDs/GIDs and other Unix settings (on the „Unix attributes“ tab in ADUC). It's easier if you enable this feature during provisioning, than setting this up later by hand. And even if you don't required it (yet), it's not affecting your installation.

Important notes on the provisioning:

  • As of Samba 4.0.0rc1 the provision command uses the Samba Internal DNS server by default. If you would like to use Bind as DNS backend, add --dns-backend=BIND9_DLZ to the provisioning command. This decission isn't final. You can switch the backend whenever it's necessary.
  • If you re-run the provisioning, you need to remove the /usr/local/samba/etc/smb.conf! You may also need to remove the samaba database files if they were generated rm -rf /usr/local/samba/private/*
  • The admin password need to fulfill the password complexity requirements. This means at least one uppercase letter, one number, and at least eight characters length. If you don't use a complex enough password, the provision script will fail, and you will need to start over with a better password (remove /usr/local/samba/private/ and /usr/local/samba/etc/).

Classicupgrade (Migrating a Samba NT4-style domain to AD)

If you plan to migrate an existing Samba NT4 domain to Samba AD, see the Classicupgrade HowTo.

Starting Your Samba AD DC

Note: If you are running any smbd, nmbd or winbindd processes from previous installations, they need to be stopped before starting samba from your new installation!

If you are planning to run Samba as a production server, then simply run the binary as root:

# /usr/local/samba/sbin/samba

That will run Samba in 'standard' mode, which is suitable for production use. Samba doesn't yet have init scripts included for each platform, but writing one for your platform should not be difficult. There are some example scripts on the Samba4 Init-Script page.

If you are running Samba as a developer you may find the following more useful:

# /usr/local/samba/sbin/samba -i -M single

This will start Samba with all log messages printed to stdout, and restricting it to a single process. That mode of operation makes debugging Samba with gdb easier. To launch Samba under gdb, run as follows:

# gdb --args /usr/local/samba/sbin/samba -i -M single

Testing Connectivity to Your Samba AD DC

First check that you have the right version of smbclient by running:

 $ /usr/local/samba/bin/smbclient --version

This should show you a version starting with "Version 4.x".

Now run this command to list the shares on your Samba server:

$ /usr/local/samba/bin/smbclient -L localhost -U%

       Sharename       Type      Comment
       ---------       ----      -------
       netlogon        Disk
       sysvol          Disk
       IPC$            IPC       IPC Service (Samba 4.x.y)

The output of the command should be similar to what is shown. The netlogon and sysvol shares are default shares needed for Active Directory server operation and created in your smb.conf during provisioning/upgrading.

If the command failed, restart samba:

# killall samba
# /usr/local/samba/sbin/samba

To test that authentication is working, you should try to connect to the netlogon share, using the Administrator account created during provisioning. The output of the command should be similar to what is shown below:

$ smbclient //localhost/netlogon -UAdministrator% -c 'ls'

Domain=[SAMDOM] OS=[Unix] Server=[Samba 4.x.y]
  .                                   D        0  Tue Dec 11 20:00:00 2012
  ..                                  D        0  Tue Dec 11 20:00:00 2012

Configure DNS

A working DNS setup is essential to the correct operation of Samba and AD. Without the right DNS entries, Kerberos won't work, which in turn means that many of the basic features won't work! It is worth spending some extra time to ensure your DNS setup is correct, as debugging problems caused by mis-configured DNS can take a lot of time later on. To manage DNS entries the DNS MMC on a Windows client can be used, or samba-tool on Linux - see DNS Administration for more information.

DNS Backends

For additional information on the supported DNS backends and a decission aid, which fits best to your needs, see the DNS page.

Samba Internal DNS Server

Per default Samba uses its Internal DNS and no further configuration is required.

Typically you want the DNS server to forward requests that it isn't resposible for. Simply add

dns forwarder = {IP-Address of the DNS you want to forward to}

to your smb.conf and restart Samba.

To enable the Internal DNS to start, port 53 udp/tcp must not be taken by any other program (like another DNS server, Dnsmasq, etc.). You'll see errors in your samba logfile, if Samba can't bind to port 53:


To check, which program is listening on port 53, run as root

# netstat -tunpe | grep ":53"

It should return only samba processes, bound to this port.

More information about troubleshooting can be found on the Samba Troubleshooting page.

BIND as DNS backend

If you chose BIND9_DLZ in your provisioning, see the Bind as DNS backend HowTo for additional setup instructions. There you will find much information on how to setup and configure Bind in general and how to configure it with Samba AD. If you provisioned your DC with the Internal DNS, you can switch to BIND, whenever it's necessary.

Configure /etc/resolv.conf

For the local DNS lookups to resolve correctly, we need to modify the server's /etc/resolv.conf. The following example should be sufficient to have DNS resolve properly (adapt the domain and IP to your environment):

  • Note: If your server is set up to receive its IP configuration via DHCP, the /etc/resolv.conf file might be automatically updated. Refer to your distributions documentation on how to stop/change this behavior, although DHCP is not recommended on a DC.

Testing DNS

To test that DNS is working properly, run the following commands and compare the output to what is shown:

$ host -t SRV has SRV record 0 100 389
$ host -t SRV has SRV record 0 100 88
$ host -t A has address

The answers you get, should be similar to the ones above (adjusted for your domain name, hostname and IP). If you get any errors, carefully check your system logs to locate the problem.

Configure Kerberos

Kerberos configuration is handled by the krb5.conf file. This file is typically located in the /etc/ directory. Please refer to your distribution documentation for the location of this file on your system. There is a sample file created during provisioning located at /usr/local/samba/share/setup/krb5.conf, that is a suitable replacement for an existing file. Its default content is:

        default_realm = ${REALM}
        dns_lookup_realm = false
        dns_lookup_kdc = true
  • Note: If you have forgotten your realm, run samba-tool testparm --suppress-prompt | grep realm, to find it out.

Testing Kerberos

The simplest test is to use the kinit command as follows:

$ kinit administrator@SAMDOM.EXAMPLE.COM
  • Note: You must specify your domain realm in uppercase letters!
  • Note: Depending on your distribution, kinit may just return you to a prompt, however, some distributions may return something like Warning: Your password will expire in x days on ...

To verify that Kerberos is working, and that you received a ticket, run:

$ klist
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: administrator@SAMDOM.EXAMPLE.COM
Valid starting     Expires            Service principal
02/10/13 19:39:48  02/11/13 19:39:46  krbtgt/SAMDOM.EXAMPLE.COM@SAMDOM.EXAMPLE.COM

If either kinit or klist do not exist on your system, refer to Samba_4_OS_Requirements on how to install the necessary packages.

You can also test Kerberos form a remote client, but you must first configure the client's krb5.conf and resolve.conf as shown previously.

  • Note: If you are using a client behind NAT then you have to add the following to the krb5.conf on the domain controller:
        check-ticket-addresses = false
  • Note: If provision generated you a password and you forgot it or didn't get it saved in some way, you can use samba-tool user setpassword administrator as root to reset it.

Configure NTP (Optional, but highly recommended)

Active Directory requires an accurate time synchronization between the clients and the DC(s). It's highly recommended to run NTP or another form of synchronization. The Configure NTP page shows the full NTP configuration process including SELinux policies.

Optional and Further Information

The Samba Wiki provides you many useful further documentation on administrating your DC (Backup and recovery, Setup and configure file shares, etc.), daily work (Configuring a windows client for AD, Samba AD Management from windows, etc.) or Authenticating other services against AD.

See the Samba Wiki user documentation page for many further HowTos, tutorials and information.

Report Your Success/Failure!

Samba as a DC is still developing rapidly. We'd like to hear from users about their successes and failures. We would encourage you to report your successes and failures to the samba-technical mailing list on