{"id":123707,"date":"2022-04-08T08:00:00","date_gmt":"2022-04-08T08:00:00","guid":{"rendered":"https:\/\/fedoramagazine.org\/?p=36175"},"modified":"2022-04-08T08:00:00","modified_gmt":"2022-04-08T08:00:00","slug":"samba-as-ad-and-domain-controller","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/04\/08\/samba-as-ad-and-domain-controller\/","title":{"rendered":"Samba as AD and Domain Controller"},"content":{"rendered":"<p>Having a server with Samba providing AD and Domain Controller functionality will provide you with a very mature and professional way to have a centralized place with all users and groups information. It will free you from the burden of having to manage users and groups on each server. This solution is useful for authenticating applications such as WordPress, FTP servers, HTTP servers, you name it.<\/p>\n<p>This step-by-step tutorial about setting up Samba as an AD and Domain Controller will demonstrate to you how you can achieve this solution for your network, servers, and applications.<\/p>\n<p> <span id=\"more-36175\"><\/span> <\/p>\n<h2>Pre-requisites<\/h2>\n<p>A fresh Fedora Linux 35 server installation.<\/p>\n<h2>Definitions<\/h2>\n<p><strong>Hostname<\/strong>: dc1<br \/><strong>Domain<\/strong>: onda.org<br \/><strong>IP<\/strong>: 10.1.1.10\/24<\/p>\n<h2>Considerations<\/h2>\n<ul>\n<li>Once the domain was chosen, you can&#8217;t change it, be wise;<\/li>\n<li>In the <em>\/etc\/hosts<\/em> file, the server name can&#8217;t be on <em>127.0.0.1<\/em> line, it must be on its IP address line;<\/li>\n<li>Use a fixed IP address for the server, as a result, the server&#8217;s IP won&#8217;t change;<\/li>\n<li>Once you provision the DC server, do not provision another one, join other ones to the domain instead;<\/li>\n<li>For the DNS server, we will choose <em>SAMBA_INTERNAL<\/em>, so we can have the DNS forwarding feature;<\/li>\n<li>It is necessary to have a time synchronization service running in the server, like <em>chrony <\/em>or <em>ntp<\/em>, so you can avoid numerous problems from not having the server and clients synchronized with the same time;<\/li>\n<\/ul>\n<h2>Samba installation<\/h2>\n<p>Let&#8217;s install the required software to get through this guide. It will provide all the applications you will need.<\/p>\n<pre class=\"wp-block-preformatted\">sudo dnf install samba samba-dc samba-client heimdal-workstation<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"941\" height=\"583\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller.gif\" alt=\"Samba installation process\" class=\"wp-image-36180\" \/><\/a><figcaption>Samba installation<\/figcaption><\/figure>\n<h2>Configurations<\/h2>\n<p>For setting up Samba as an AD and Domain Controller, you will have to prepare the environment with a functional configuration before you start using it.<\/p>\n<h3>Firewall<\/h3>\n<p>You will need to allow some UDP and TCP ports through the firewall so that clients will be able to connect to the Domain Controller.<\/p>\n<p>I will show you two methods to add them. Choose the one that suits you best.<\/p>\n<h4>First method<\/h4>\n<p>This is the most straightforward method, <em>firewalld <\/em>comes with a service with all ports needed to open Samba DC, which is called <em>samba-dc<\/em>. Add it to the firewall rules:<\/p>\n<p>Add the service:<\/p>\n<pre class=\"wp-block-preformatted\">sudo firewall-cmd --permanent --add-service samba-dc<\/pre>\n<h4>Second method<\/h4>\n<p>Alternatively, you can add the rules from the command line:<\/p>\n<pre class=\"wp-block-preformatted\">sudo firewall-cmd --permanent --add-port={53\/udp,53\/tcp,88\/udp,88\/tcp,123\/udp,135\/tcp,137\/udp,138\/udp,139\/tcp,389\/udp,389\/tcp,445\/tcp,464\/udp,464\/tcp,636\/tcp,3268\/tcp,3269\/tcp,49152-65535\/tcp}<\/pre>\n<p>Reload <em>firewalld<\/em>:<\/p>\n<pre class=\"wp-block-preformatted\">sudo firewall-cmd --reload<\/pre>\n<p>For more information about <em>firewalld<\/em>, check the following article: <a href=\"https:\/\/fedoramagazine.org\/control-the-firewall-at-the-command-line\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Control the firewall at the command line<\/a><\/p>\n<h3>SELinux<\/h3>\n<p>To run a Samba DC and running with SELinux in enforcing mode, it is necessary to set some samba booleans for SELinux to on. After these booleans are set, it should not be necessary to disable SELinux.<\/p>\n<pre class=\"wp-block-preformatted\">sudo setsebool -P samba_create_home_dirs=on samba_domain_controller=on samba_enable_home_dirs=on samba_portmapper=on use_samba_home_dirs=on<\/pre>\n<p>Restore the default SELinux security contexts for files:<\/p>\n<pre class=\"wp-block-preformatted\">sudo restorecon -Rv \/<\/pre>\n<h3>Samba<\/h3>\n<p>First, remove the <em>\/etc\/samba\/smb.conf<\/em> file if it exists:<\/p>\n<pre class=\"wp-block-preformatted\">sudo rm \/etc\/samba\/smb.conf<\/pre>\n<p>Samba uses its own DNS service, and for that reason, the service won&#8217;t start if <em>systemd-resolved<\/em> is running, that is why it is necessary to edit its configuration to stop listening on port 53 and use Samba&#8217;s DNS.<\/p>\n<p>Create the directory<em> \/etc\/systemd\/resolved.conf.d\/<\/em> if it does not exist:<\/p>\n<pre class=\"wp-block-preformatted\">sudo mkdir \/etc\/systemd\/resolved.conf.d\/<\/pre>\n<p>Create the file <em>\/etc\/systemd\/resolved.conf.d\/custom.conf<\/em> that contains the custom config:<\/p>\n<pre class=\"wp-block-preformatted\">[Resolve]\nDNSStubListener=no\nDomains=onda.org\nDNS=10.1.1.10<\/pre>\n<p><strong>Remember to change the <em>DNS <\/em>and <em>Domains <\/em>entries to be your Samba DC server.<\/strong><\/p>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-1.gif\"><img decoding=\"async\" loading=\"lazy\" width=\"941\" height=\"583\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-1.gif\" alt=\"\" class=\"wp-image-36243\" \/><\/a><\/figure>\n<p>Restart the <em>systemd-resolved<\/em> service:<\/p>\n<pre class=\"wp-block-preformatted\">sudo systemctl restart systemd-resolved<\/pre>\n<p>Finally, provision the Samba configuration. <em>samba-tool<\/em> provides every step needed to make Samba an AD server.<\/p>\n<p>Using the <em>samba-tool<\/em>, provision the Samba configuration:<\/p>\n<pre class=\"wp-block-preformatted\">sudo samba-tool domain provision --server-role=dc --use-rfc2307 --dns-backend=SAMBA_INTERNAL --realm=ONDA.ORG --domain=ONDA --adminpass=sVbOQ66iCD3hHShg<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-2.gif\"><img decoding=\"async\" loading=\"lazy\" width=\"941\" height=\"583\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-2.gif\" alt=\"Using samba-tool to provision a domain\" class=\"wp-image-36181\" \/><\/a><figcaption>Samba domain provisioning<\/figcaption><\/figure>\n<p>The <em>\u2010\u2010use-rfc2307<\/em> argument provides POSIX attributes to Active Directory, which stores Unix user and group information on LDAP (<a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc2307.txt\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">rfc2307.txt<\/a>).<\/p>\n<p>Make sure that you have the correct <em>dns forwarder<\/em> address set in <em>\/etc\/samba\/smb.conf<\/em>. Concerning this tutorial, it should be <strong>different<\/strong> from the server&#8217;s own IP address 10.1.1.10, in my case I set to 8.8.8.8, however your mileage may vary:<\/p>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-3.gif\"><img decoding=\"async\" loading=\"lazy\" width=\"941\" height=\"583\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-3.gif\" alt=\"Changing the dns forwarder value on \/etc\/samba\/smb.conf file\" class=\"wp-image-36256\" \/><\/a><figcaption>Changing the <em>dns forwarder<\/em> value on <em>\/etc\/samba\/smb.conf<\/em> file<\/figcaption><\/figure>\n<p>After changing the <em>dns forwarder value<\/em>, restart <em>samba <\/em>service:<\/p>\n<pre class=\"wp-block-preformatted\">sudo systemctl restart samba<\/pre>\n<h3>Kerberos<\/h3>\n<p>After Samba installation, it was provided a <em>krb5.conf<\/em> file that we will use:<\/p>\n<pre class=\"wp-block-preformatted\">sudo cp \/usr\/share\/samba\/setup\/krb5.conf \/etc\/krb5.conf.d\/samba-dc<\/pre>\n<p>Edit <em>\/etc\/krb5.conf.d\/samba-dc<\/em> content to match your organization information:<\/p>\n<pre class=\"wp-block-preformatted\">[libdefaults]<br \/> default_realm = ONDA.ORG<br \/> dns_lookup_realm = false<br \/> dns_lookup_kdc = true<br \/><br \/>[realms]<br \/>ONDA.ORG = {<br \/> default_domain = ONDA<br \/>}<br \/><br \/>[domain_realm]<br \/> dc1.onda.org = ONDA.ORG<\/pre>\n<h3>Starting and enabling Samba on boot time<\/h3>\n<p>To make sure that Samba will start on system initialization, enable and start it:<\/p>\n<pre class=\"wp-block-preformatted\">sudo systemctl enable samba<br \/>sudo systemctl start samba<\/pre>\n<h2>Testing<\/h2>\n<h3>Connectivity<\/h3>\n<pre class=\"wp-block-preformatted\">$ smbclient -L localhost -N<\/pre>\n<p>As a result of <em>smbclient <\/em>command, shows that connection<em> <\/em>was successful.<\/p>\n<pre class=\"wp-block-preformatted\">Anonymous login successful<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sharename &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Type &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Comment<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--------- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;---- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-------<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sysvol &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Disk<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;netlogon &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Disk<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IPC$ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IPC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IPC Service (Samba 4.15.6)<br \/>SMB1 disabled -- no workgroup available<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-4.gif\"><img decoding=\"async\" loading=\"lazy\" width=\"501\" height=\"196\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-4.gif\" alt=\"Testing connection with smbclient tool\" class=\"wp-image-36177\" \/><\/a><figcaption><em>smbclient <\/em>connection test<\/figcaption><\/figure>\n<p>Now, test the <em>Administrator <\/em>login to <em>netlogon <\/em>share:<\/p>\n<pre class=\"wp-block-preformatted\">$ smbclient \/\/localhost\/netlogon -UAdministrator -c 'ls'<\/pre>\n<pre class=\"wp-block-preformatted\">Password for [ONDA\\Administrator]:<br \/>&nbsp;&nbsp;. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 &nbsp;Sat Mar 26 05:45:13 2022<br \/>&nbsp;&nbsp;.. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 &nbsp;Sat Mar 26 05:45:18 2022<br \/><br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8154588 blocks of size 1024. 7307736 blocks available<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-5.gif\"><img decoding=\"async\" loading=\"lazy\" width=\"615\" height=\"151\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-5.gif\" alt=\"smbclient Administrator connection test\" class=\"wp-image-36178\" \/><\/a><figcaption><em>smbclient Administrator <\/em>connection test<\/figcaption><\/figure>\n<h3>DNS test<\/h3>\n<p>To test if the name resolution is working, execute the following commands:<\/p>\n<pre class=\"wp-block-preformatted\">$ host -t SRV _ldap._tcp.onda.org.<br \/>_ldap._tcp.onda.org has SRV record 0 100 389 dc1.onda.org.<\/pre>\n<pre class=\"wp-block-preformatted\">$ host -t SRV _kerberos._udp.onda.org.<br \/>_kerberos._udp.onda.org has SRV record 0 100 88 dc1.onda.org.<\/pre>\n<pre class=\"wp-block-preformatted\">$ host -t A dc1.onda.org.<br \/>dc1.onda.org has address 10.1.1.10<\/pre>\n<p>If you get the error: <\/p>\n<pre class=\"wp-block-preformatted\"><em>-bash: host: command not found<\/em> <\/pre>\n<p>Install the <em>bind-utils<\/em> package:<\/p>\n<pre class=\"wp-block-preformatted\">sudo dnf install bind-utils<\/pre>\n<h3>Kerberos test<\/h3>\n<p>Testing Kerberos is important because it generates the required tickets to let clients authenticate with encryption. It heavily relies on correct time. <\/p>\n<p>It can&#8217;t be stressed enough to have date and time set correctly, and that is why it is so important to have a time synchronization service running on both clients and servers.<\/p>\n<pre class=\"wp-block-preformatted\">$ \/usr\/lib\/heimdal\/bin\/kinit administrator<br \/>$ \/usr\/lib\/heimdal\/bin\/klist<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-6.gif\"><img decoding=\"async\" loading=\"lazy\" width=\"568\" height=\"185\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-6.gif\" alt=\"Kerberos ticket validation\" class=\"wp-image-36179\" \/><\/a><figcaption>Kerberos ticket validation<\/figcaption><\/figure>\n<h2>Adding a user to the Domain<\/h2>\n<p><em>samba-tool<\/em> provides us an interface for executing Domain administration tasks, so we can add a user to the Domain easily. <\/p>\n<p>The <em>samba-tool<\/em> help is very comprehensive:<\/p>\n<pre class=\"wp-block-preformatted\">$ samba-tool user add --help<\/pre>\n<p>Adding user <em>danielk <\/em>to the domain:<\/p>\n<pre class=\"wp-block-preformatted\">sudo samba-tool user add danielk --unix-home=\/home\/danielk --login-shell=\/bin\/bash --gecos 'Daniel K.' --given-name=Daniel --surname='K\u00fchl' --mail-address='danielk@onda.org'<\/pre>\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-7.gif\"><img decoding=\"async\" loading=\"lazy\" width=\"941\" height=\"216\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2022\/04\/samba-as-ad-and-domain-controller-7.gif\" alt=\"Adding user to the Domain using samba-tool\" class=\"wp-image-36258\" \/><\/a><figcaption>Adding user to the Domain<\/figcaption><\/figure>\n<p>To list the users on Domain:<\/p>\n<pre class=\"wp-block-preformatted\">sudo samba-tool user list<\/pre>\n<h2>Wrap up and conclusion<\/h2>\n<p>We started out by installing Samba and required applications in a fresh Fedora Linux 35 installation. We&#8217;ve also explained the problems that this solution solves. Thereafter, we did an initial configuration that prepares the environment to be ready to Samba to operate as an AD and Domain Controller.<\/p>\n<p>Then, we proceeded to cover how to have Samba up and running alongside Fedora Linux security features, like having it working with <em>firewalld <\/em>and SELinux enabled. We did some important testing to make sure everything was fine and ended by showing a bit on how to administrate users using <em>samba-tool<\/em>.<\/p>\n<p>To summarize, if you want to establish a robust solution for centralizing authentication across your network, servers (If one wanted to, one could even join a Windows 10 client to this Samba domain [<em>tested with Windows 10 Professional version 20H2<\/em>]) and services, consider using this approach as part of your infrastructure.<\/p>\n<p>Now that you know how to have a Samba as AD and Domain Controller solution, what would you like to see covered next? Share your thoughts in the <a href=\"https:\/\/fedoramagazine.org\/samba-as-ad-and-domain-controller\/#comments\" rel=\"nofollow\">comments below<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Having a server with Samba providing AD and Domain Controller functionality will provide you with a very mature and professional way to have a centralized place with all users and groups information. It will free you from the burden of having to manage users and groups on each server. This solution is useful for authenticating [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":123708,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[1312,416,1313,45,1314,43,1315,418,1316,46,47,1041,1317],"class_list":["post-123707","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fedora-os","tag-accounts","tag-active-directory","tag-domain-controller","tag-fedora","tag-file-server","tag-for-system-administrators","tag-kdc","tag-kerberos","tag-ldap","tag-magazine","tag-news","tag-samba","tag-smb"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/123707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=123707"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/123707\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/123708"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=123707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=123707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=123707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}