Domains and directory services¶
Practical 6.6 domains-and-directory-services-annex.pdf · PDF
At school you log in with the same user name on any PC of any classroom. Your password is the same everywhere, and when you change it, it changes everywhere. Nobody walked round the building to create your account on two hundred machines. How?
Tramuntana Apps has 12 people and 12 PCs. Today every PC keeps its own list of accounts, like your VMs. Marta must be able to sit at any PC, so there are 12 accounts called marta. For all twelve people: 144 accounts. Marta changes her password: 12 changes. Pau leaves on Friday: 12 accounts to delete, and the one somebody forgets is a door left open. This page replaces those 144 accounts with 12.
What you will learn
- Why a workgroup stops working as a company grows, and what a domain changes
- Define directory, domain controller, realm and NetBIOS name
- The three protocols under a domain: DNS finds, Kerberos proves, LDAP looks up
- How a Kerberos ticket proves who you are without your password ever reaching the service
- Build a Samba Active Directory domain controller and verify it
- Why "in a domain my password is sent to every server" is exactly backwards
Workgroup vs domain¶
A workgroup is a set of computers where each one keeps its own list of accounts.
A domain is a set of computers that trust one central server to know every user, group and computer, and to check every password.
In a domain each PC is told: "do not check passwords yourself, ask that server". Three new words:
- The central list is the directory: a database of objects (users, groups, computers) arranged in a tree.
- The server that holds it and answers the logins is the domain controller (DC).
- The domain has a DNS-style name,
tramuntana.internal, and a short old-style name of up to 15 characters, the NetBIOS name:TRAMUNTANA. Kerberos calls the domain a realm and writes it in capitals:TRAMUNTANA.INTERNAL.
flowchart TB
subgraph WG ["Workgroup: every PC has its own list"]
direction LR
P1["<b>PC 1</b><br>12 accounts"]
P2["<b>PC 2</b><br>12 accounts"]
P3["<b>PC 3</b><br>12 accounts"]
end
subgraph DOM ["Domain: one list, on the DC"]
DC["<b>dc1</b><br>domain controller<br>the directory: 12 users"]
D1["PC 1"] -->|"ask the DC"| DC
D2["PC 2"] -->|"ask the DC"| DC
D3["PC 3"] -->|"ask the DC"| DC
end
| Workgroup | Domain | |
|---|---|---|
| Accounts live | On each computer | Once, in the directory on the DC |
| Marta logs in | Only where she has a local account | On any computer that has joined |
| Password change | Once per computer | Once |
| Rules (security policies) | Set on each computer by hand | Set centrally, with Group Policy |
| If the central server is down | Nothing changes | Logins have a problem: companies run two DCs |
Why .internal and not .local
The domain name must never clash with a real Internet name. In July 2024 ICANN, the organisation that manages top-level domains, reserved .internal for private networks. Do not use .local: it belongs to another protocol, mDNS, and Samba's documentation warns against it.
Careful: the DC does not store everybody's files
A domain controller stores identities and rules. Files stay on file servers, like ubu-srv.
Three jobs, three protocols¶
A domain is not one magic program. It is three protocols working together, and you already know two of them.
| Job | Protocol · port | In one sentence |
|---|---|---|
| Find the controller | DNS · 53 | The PC asks DNS for an SRV record: "who offers LDAP and Kerberos for tramuntana.internal?" |
| Prove who you are | Kerberos · 88 | The DC checks your password once and gives you a ticket |
| Look up things | LDAP · 389 | The language for asking the directory: "which groups is marta in?" |
An SRV record is a DNS record that answers "which host offers this service, on which port?" — not just "which address has this name?".
The wristband: how Kerberos works¶
Picture a music festival. At the entrance you show your ID once and get a wristband valid for the day. At every bar you show the wristband, never your ID. The bar staff do not know you; they trust the wristband because only the entrance can make one. And a wristband has an end time.
That is Kerberos. The entrance is the KDC (Key Distribution Centre), a service running on the domain controller.
sequenceDiagram
participant M as Marta's PC
participant K as KDC on dc1 (the entrance)
participant F as File server (a bar)
M->>K: I am marta, here is proof I know my password
K-->>M: TGT (the wristband), valid until a set time
M->>K: My TGT. I want the file server, please
K-->>M: Service ticket for the file server
M->>F: Service ticket
F-->>M: Folder opened
- Marta proves to the KDC that she knows her password. She gets a ticket-granting ticket (TGT): the wristband.
- To use the file server she shows the TGT to the KDC (no password this time) and gets a service ticket for that server.
- She gives the service ticket to the file server, which checks it was made by the KDC and opens the folder.
How many times did Marta type her password? Once. Did the file server ever see it? Never.
Clocks matter
Tickets carry times. If Marta's PC thinks it is 3 pm and the KDC thinks it is 4 pm, her ticket looks expired or not yet valid. Kerberos refuses when two clocks differ by more than 5 minutes.
Careful: your password does not travel to every server
It is the opposite. The password is checked in one place, the KDC. Everything else only ever sees tickets.
Three old protocols and two products¶
A domain is built from parts older than you.
- Kerberos comes from MIT in the 1980s. Project Athena put student workstations on a network where anybody could listen, so its engineers designed a login for an untrusted network and presented it in 1988. The name is the three-headed dog that guards the underworld in Greek myth: user, service, KDC. Version 5 became an Internet standard in 1993 (RFC 1510; today RFC 4120, from 2005).
- LDAP comes from the University of Michigan, 1993. Tim Howes, with Wengyik Yeong and Steve Kille, wanted the campus directory reachable from an ordinary PC. The existing standard, X.500, was too heavy, so they wrote a Lightweight Directory Access Protocol (RFC 1487; version 3 in 1997; today RFC 4511, from 2006).
- Active Directory (AD), Microsoft's directory, shipped with Windows 2000 Server on 17 February 2000: DNS, Kerberos and LDAP joined into one product. It is still what most companies with Windows PCs use.
- Samba 4.0, released on 11 December 2012 after about ten years of work, was the first free implementation of an Active Directory domain controller. A Windows PC joins it just as it would join a Microsoft one.
Why Samba for Tramuntana¶
Windows Server is the usual case in companies, but it is proprietary (evaluation versions expire) and needs a full Windows Server VM. A Samba AD DC is free software and fits in a small Linux VM with 2 GB of RAM and no desktop, next to win11 on a classroom PC. Everything you learn here — domain, DC, join, users, groups, OUs, policies — has the same names on Windows Server.
One Samba package can be a file server or a domain controller, but not both with one configuration. That is why the controller is a new VM, dc1 at 192.168.122.20, and ubu-srv (192.168.122.10) stays the file, print and application server.
Build the domain controller¶
This is Practical 6.6, part 1: the steps are on the Practical sheet. Here is what each one does.
1. A name and a fixed address¶
Samba asks for three things before anything is installed: a host name shorter than 15 characters, a static address, and a host name that resolves to that address and not to 127.0.x.x.
sudo hostnamectl set-hostname dc1
sudo nano /etc/netplan/60-static.yaml # 192.168.122.20/24, gateway and DNS 192.168.122.1
sudo chmod 600 /etc/netplan/60-static.yaml
sudo netplan apply
sudo nano /etc/hosts # replace the 127.0.1.1 line: 192.168.122.20 dc1.tramuntana.internal dc1
hostname -f
sudo grep -n '^%admin' /etc/sudoers # must print nothing
hostname -f must print dc1.tramuntana.internal. The last line is the sudoers audit on a new machine: a fresh Ubuntu makes the group admin root, and this domain is about to get a group called admin.
2. Packages and services¶
sudo apt update
sudo apt install -y samba-ad-dc krb5-user bind9-dnsutils
sudo systemctl disable --now smbd nmbd winbind
sudo systemctl mask smbd nmbd winbind
sudo systemctl unmask samba-ad-dc
sudo systemctl enable samba-ad-dc
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.orig
smbd, nmbd and winbind are the file-server programs. On a DC one program, samba, starts what it needs, so the others are switched off and masked (forbidden to start). The old smb.conf is moved away because the next step writes a new one.
3. Provision the domain¶
Provisioning means creating the domain: the directory database, the DNS zone, the Kerberos keys and the first administrator.
| Question | Answer |
|---|---|
Realm: |
TRAMUNTANA.INTERNAL |
Domain [TRAMUNTANA]: |
Enter |
Server Role (dc, member, standalone) [dc]: |
Enter |
DNS backend (...) [SAMBA_INTERNAL]: |
Enter |
DNS forwarder IP address ... |
192.168.122.1 |
Administrator password: |
At least 7 characters, mixing capitals, small letters and digits |
The forwarder is where the DC sends questions about names it does not own, such as debian.org: the network's normal DNS. Capital letters matter in the realm, and a domain cannot be renamed later.
4. The DC becomes its own DNS client¶
sudo systemctl disable --now systemd-resolved
sudo unlink /etc/resolv.conf
printf 'nameserver 127.0.0.1\nsearch tramuntana.internal\n' | sudo tee /etc/resolv.conf
sudo cp -f /var/lib/samba/private/krb5.conf /etc/krb5.conf
sudo systemctl start samba-ad-dc
Ubuntu's small resolver occupies port 53, and Samba's DNS server needs that port. So the resolver is switched off and the DC asks itself (127.0.0.1). The Kerberos client configuration that provisioning generated is copied into place. Then systemctl status samba-ad-dc must say active (running).
5. Verify: find, prove, look up¶
host -t SRV _ldap._tcp.tramuntana.internal.
host -t SRV _kerberos._udp.tramuntana.internal.
host -t A dc1.tramuntana.internal.
dig +short debian.org
kinit Administrator
klist
smbclient -L localhost -N
| Command | What you should see | What it proves |
|---|---|---|
host -t SRV _ldap... |
has SRV record 0 100 389 dc1.tramuntana.internal. |
DNS finds the LDAP service: priority 0, weight 100, port 389, host dc1 |
host -t SRV _kerberos... |
... 0 100 88 dc1.tramuntana.internal. |
DNS finds Kerberos on port 88 |
host -t A dc1... |
has address 192.168.122.20 |
The DC's own name resolves |
dig +short debian.org |
An Internet address | The forwarder works |
kinit + klist |
Default principal: administrator@TRAMUNTANA.INTERNAL and a ticket krbtgt/TRAMUNTANA.INTERNAL@... |
Kerberos works: that krbtgt ticket is the wristband, for real |
smbclient -L |
The shares sysvol and netlogon |
The DC's own shares are up |
A Windows PC that wants to join the domain asks exactly the SRV question of the first line.
6. The domain's password policy¶
On Samba 4.23 it prints, among others: Password complexity: on, Minimum password length: 7, Maximum password age (days): 42. The password policy you once set on one machine is now set once, for the whole domain. Finish with a snapshot of dc1 called dc-ready.
If something fails
- Provisioning complains that
smb.confexists: the last line of step 2 was skipped. samba-ad-dcdoes not start and the log mentions port 53:systemd-resolvedis still running.kinitcannot find the KDC, or shows a strange realm such asATHENA.MIT.EDU:/etc/krb5.confwas not copied. That default realm is MIT's Project Athena itself.
Key takeaways¶
- In a workgroup every PC keeps its own accounts; in a domain one directory on the domain controller knows every user, group and computer.
- Our domain:
tramuntana.internal, realmTRAMUNTANA.INTERNAL, NetBIOS nameTRAMUNTANA, ondc1(192.168.122.20). - DNS finds the controller (SRV records), Kerberos proves identity with tickets, LDAP looks things up in the directory.
- Kerberos checks your password once, at the KDC, and gives you a TGT; services only see tickets. Clocks must agree within 5 minutes.
- Active Directory (2000) joined the three protocols into one product; Samba has implemented a compatible DC since version 4.0 (2012).
- A controller is not finished until it has been verified: SRV records, a
klistticket, a working forwarder.
Quick check¶
1. In a domain, where does Marta's account exist?
- Once, in the directory on the domain controller
- On every PC of the company, kept in sync
- Only on the PC she uses most
- In a file she carries on a USB stick
In a domain each account exists once, in the directory on the DC. Every joined PC asks the DC instead of keeping its own copy.
2. How does a PC find the domain controller of tramuntana.internal?
- It asks DNS for the SRV records of the domain
- It tries every address of the network in turn
- It reads the /etc/hosts file of the controller
- It asks Kerberos for the address of the DC
Finding is the job of DNS: an SRV record answers "which host offers LDAP (or Kerberos) for this domain, on which port?". Our answer is dc1, port 389.
3. What does a Kerberos ticket let Marta do?
- Prove who she is to a service without sending it her password
- Read any file in the domain without permissions
- Change the security policy of the domain
- Find the address of the domain controller
The KDC checks the password once and gives a TGT; with it Marta gets service tickets. The file server trusts the ticket and never sees the password.
4. Logins fail on one PC only. Its clock is 15 minutes late. Why does that matter?
- Kerberos tickets are refused when clocks differ by more than 5 minutes
- DNS answers only to PCs with the correct time
- LDAP gets slower when the clock is late
- It does not matter: the password is still right
Kerberos tickets carry validity times. With more than 5 minutes of difference a ticket looks expired or not yet valid, so the login fails even with the right password.
5. Which protocol is used to ask the directory which groups marta is in?
- LDAP
- DNS
- SMB
- DHCP
LDAP (Lightweight Directory Access Protocol, port 389) is the language for querying the directory. DNS finds the DC; Kerberos proves identity.
6. Why does the classroom domain use the ending .internal instead of .local?
- .internal is reserved for private networks, and .local belongs to mDNS
- .local is reserved for Windows Server domains only
- .internal is shorter and easier to type
- Samba refuses any ending other than .internal
In July 2024 ICANN reserved .internal for private networks, so it can never clash with a real Internet name. .local is used by mDNS and Samba's documentation advises against it.
7. A small company wants one place for all accounts but has no budget for Windows Server licences. Select the two true statements.
- A Samba AD DC on a small Linux VM can be the domain controller
- Windows PCs can join a Samba domain as they would join a Microsoft one
- Without Windows Server the company has to stay a workgroup
- The domain controller should also be the main file server, to save a VM
Samba has implemented an Active Directory DC since 4.0 (2012), and Windows clients join it normally. Samba's documentation advises against using a DC as a general file server, which is why dc1 and ubu-srv are separate machines.
You own a domain with one computer in it: the controller itself. Next, other machines join it and Marta logs in where she has no local account — Joining a domain.