Difference between revisions of "Setting up Samba as an Active Directory Domain Controller"

m (Fix link to the 'changing DNS backend' page)
m (Fix link)
Line 300: Line 300:
= Optional and Further Information =
= Optional and Further Information =
The Samba Wiki provides you many useful further documentation on administrating your DC ([[Backup_and_Recovery|Backup and recovery]], [[Setup_and_configure_file_shares|Setup and configure file shares]], etc.), daily work ([[Configuring_a_windows_client_for_AD|Configuring a windows client for AD]], [[Installing_RSAT_on_Windows_for_AD_Management|Installing RSAT on Windows for AD Management]], etc.) or [[Authenticating_other_services_against_AD|Authenticating other services against AD]].
The Samba Wiki provides you many useful further documentation on administrating your DC ([[Backup_and_Recovery|Backup and recovery]], [[Setup_and_configure_file_shares_with_Windows_ACLs|Setup and configure file shares]], etc.), daily work ([[Configuring_a_windows_client_for_AD|Configuring a windows client for AD]], [[Installing_RSAT_on_Windows_for_AD_Management|Installing RSAT on Windows for AD Management]], etc.) or [[Authenticating_other_services_against_AD|Authenticating other services against AD]].
Some thoughts on SELinux and discretionary access control permissions that can prevent login using AD users are on the [[Samba_AD_DC_access_control_settings|Samba AD DC Access Control Settings]] page.
Some thoughts on SELinux and discretionary access control permissions that can prevent login using AD users are on the [[Samba_AD_DC_access_control_settings|Samba AD DC Access Control Settings]] page.

Revision as of 23:14, 14 June 2014


This document explains how to set up 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.


This HowTo is frequently updated to reflect the latest changes. Please see the Samba Release Planning 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:

See OS Requirements for dependencies and recommendations.


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:        samdom.example.com (This will also be your realm)
NT4 Domain Name:        samdom
IP Address:   
Server Role:            DC

Provisioning Samba (Setting up a new domain)

Provisioning creates a basic database, and is only done when you configure your first Samba DC in its own domain. Once your domain is up and running and you want to add another Samba server as an additional domain controller, then please see the Join a domain as a DC HowTo.

The user running the provision command must have permission to write to the install directory, otherwise you will get permission denied errors.

To interactively provision a new domain, run:

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

This will run the provision tool, asking you various questions about the setup you require, so it is recommended, before carrying out the provision, to run:

# samba-tool domain provision --help 

This will display all the available options, the main options are:

The --realm option sets the kerberos realm and is usually the DNS domain name i.e. samdom.example.com

The --domain option sets the Domain name (this was/is also known as the 'workgroup' name) and is usually the first part of the DNS domain name in uppercase i.e. SAMDOM

The --adminpass option is where you set the main domain administrators password, This must be a complex password, at least eight characters long, containing at least one uppercase letter and at least one number

The --server-role option is where you can set what type of server role the DC will carry out, please set this to 'dc', this is the only role that is available at present, but there are plans to implement 'member server' and 'standalone' roles as soon as is practicable.

The --function-level is where to set what function level you require the domain to operate at, the default is 2003 Native but you can set it to 2000, 2003, 2008 or 2008_R2.

The --use-rfc2307 option sets your Samba AD to use posix attributes more effectively. It also adds NIS information to your AD, this allows you to administrate UIDs/GIDs and other Unix settings (on the "Unix attributes" tab in ADUC). It's easier to enable this feature during provisioning, rather than setting it up later and even if it is not required (yet), it will not affect your installation. For futher information about RFC2307, see the Using RFC2307 on a Samba DC HowTo.

You can also run the provision non-interactively by giving all the information required on the command line.

# /usr/local/samba/bin/samba-tool domain provision --realm=samdom.example.com --domain=SAMDOM --adminpass=P4ssw0rd* --use-rfc2307 --server-role='dc'

One reason to re-run the provisioning is if the admin password you choose doesn't fulfill the password complexity requirements. In this case, the provisioning script fails and you have to start all over. Make sure the password contains at least one uppercase letter, one number and is at least eight characters in length.

Notes on multiple NICs:

If you are having multiple NICs, the provisioning process auto-chooses the IPv4/v6 address of one NIC to setup the Domain Controller. To prevent this, add the following two parameters the the classicupgrade command. This would bind Samba to the given interface (eth0) and localhost (Samba should always listen on localhost, too).

--option="interfaces=lo eth0" --option="bind interfaces only=yes"

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 the DNS backend, add --dns-backend=BIND9_DLZ to the provisioning command. It's possible to switch the DNS backend at any time afterwards. See: Changing the DNS backend.
  • If you need to re-run the provisioning, you need to remove the /usr/local/samba/etc/smb.conf, you will also need to remove any generated samba database files:
  1. rm -rf /usr/local/samba/etc/smb.conf /usr/local/samba/private/*
  • If your website is example.com, the domain of your AD should be a subdomain of it, like samdom.example.com (or ad.example.com, corp.example.com). Avoid using example.com internally.

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

If you plan to migrate an existing Samba NT4 domain to Samba AD, see the Samba Classic Upgrade 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 decision 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 responsible 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 of your DC to your environment):

domain samdom.example.com
  • 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 _ldap._tcp.samdom.example.com.
_ldap._tcp.samdom.example.com has SRV record 0 100 389 dc1.samdom.example.com.
$ host -t SRV _kerberos._udp.samdom.example.com.
_kerberos._udp.samdom.example.com has SRV record 0 100 88 dc1.samdom.example.com.
$ host -t A dc1.samdom.example.com.
dc1.samdom.example.com 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 OS Requirements on how to install the necessary packages.

You can also test Kerberos from 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 a password and you forgot it or didn't save it 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 time synchronization.

The Time Synchronisation HowTo will provide all neccessary information for configuring NTP on a DC, Member Servers and Clients.

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, Installing RSAT on Windows for AD Management, etc.) or Authenticating other services against AD.

Some thoughts on SELinux and discretionary access control permissions that can prevent login using AD users are on the Samba AD DC Access Control Settings page.

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

Report Your Success/Failure!

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 mailing list on http://lists.samba.org