cd ../articles

System Networking BTS SIO labs

A Samba domain controller for Windows clients, backed by NIS

Extending the NIS lab to Windows: a Samba classic primary domain controller in an LXC container, with roaming home drives and a shared folder, reachable from the LAN through the Proxmox NAT.

  • Samba
  • NIS
  • SMB
  • Windows 10

The NIS lab gave Linux machines one set of accounts. The next question was obvious: what about Windows? This lab adds a Samba server acting as an NT4-style primary domain controller, so a Windows 10 machine can log on to the domain, get its home folder as drive H:, and share files with everyone else.

What "classic PDC" means

Samba can play two kinds of domain controller:

Classic PDC (NT4 style)Active Directory DC
Samba settingserver role = classic primary domain controllersamba-tool domain provision
DirectoryUnix accounts + Samba password databaseBuilt-in LDAP + Kerberos + DNS
Group PolicyNoYes
Fits with NISDirectlySeparate world

The point of the lab was to plug Windows into the existing NIS domain, so the classic PDC was the right tool, knowing that in a company you would deploy Active Directory (Samba AD or Windows Server) instead.

Architecture

samba-pdc.svg
Windows logon, Unix accounts
Windows logon, Unix accounts
Text version
Windows 10 client  (LAN 192.168.2.0/24)
     │  SMB 139/445 · NetBIOS 137/138
     ▼
Proxmox host  ── nftables: only these ports, only towards .105
     │
     ▼
CT 105 · samba  192.168.1.105  ── workgroup TPNIS · WINS · netlogon
     │  ypbind: Unix accounts come from NIS
     ▼
CT 102 · nis    192.168.1.102  ── NIS master (tp.nis)

The Samba container is itself a NIS client, exactly like nis-client in the previous lab. When Windows logs on as testnis, Samba maps that name to the Unix account served by NIS: same UID, same group, same home path.

The Samba configuration

/etc/samba/smb.conf · [global]
[global]
   workgroup       = TPNIS
   netbios name    = SAMBA
   server string   = PDC Samba TPNIS (NIS tp.nis)
   server role     = classic primary domain controller
   domain logons   = yes
   passdb backend  = tdbsam

   # be the browse master and the WINS server for the domain
   domain master   = yes
   local master    = yes
   preferred master = yes
   os level        = 65
   wins support    = yes
   name resolve order = wins lmhosts host bcast

   server min protocol = SMB2_10        # no SMB1
   map to guest    = never
   hosts allow     = 127. 192.168.1. 192.168.2.

   # machine accounts created automatically when a PC joins
   add machine script = /usr/sbin/useradd -K UID_MIN=20000 -K UID_MAX=29999 -M -d /nonexistent -s /usr/sbin/nologin -g machines -c "Machine %u" %u

   logon home  = \\%L\%U
   logon drive = H:
   logon path  =                          # no roaming profiles

   load printers = no
   disable spoolss = yes

A few lines deserve a word:

  • os level = 65 with the three master settings makes sure Samba wins browser elections against any Windows machine on the segment.
  • server min protocol = SMB2_10 keeps SMB1, the protocol WannaCry used, switched off. NT4-style domains work fine over SMB2.
  • add machine script: every computer that joins gets a Unix account (name ending in $) in a dedicated UID range, with no shell and no home, so it can never log in.
  • logon path = (empty) disables roaming profiles: they are slow and fragile, and the home drive is enough here.

Shares

/etc/samba/smb.conf · shares
[netlogon]
   path = /var/lib/samba/netlogon
   read only = yes
   browseable = no

[homes]
   comment = Home folder of %U
   browseable = no
   read only = no
   valid users = %S
   create mask = 0700
   directory mask = 0700
   # create the home on first logon if it does not exist yet
   root preexec = /bin/sh -c "[ -d %H ] || { mkdir -p %H && chown %U:%G %H && chmod 700 %H; }"

[commun]
   comment = Shared folder
   path = /srv/samba/commun
   read only = no
   guest ok = no
   create mask = 0664
   directory mask = 2775

[homes] is a special share: \\samba\testnis maps to that user's Unix home, and valid users = %S means only its owner can open it. The root preexec line creates the folder on first logon, so adding a user to NIS is enough; nobody has to create directories by hand. The setgid bit in 2775 on [commun] keeps new files in the shared group.

Accounts: Unix from NIS, passwords for Windows

Windows does not authenticate with Unix password hashes; it needs NT hashes. So each domain user exists twice, with the same name:

  1. Unix accountFrom NIS. Gives the UID, groups and home path. getent passwd testnis on the Samba container confirms it resolves.
  2. Samba accountIn the tdbsam database, created with smbpasswd -a testnis. Samba refuses this step if the Unix account does not exist, which is a nice consistency check.
apt install -y samba nis rpcbind
groupadd machines
testparm -s                 # validate smb.conf before restarting anything
systemctl restart smbd nmbd
smbpasswd -a testnis        # Windows password for an existing NIS user
pdbedit -L                  # list Samba accounts
smbclient -L localhost -U testnis

To let a non-root account join machines, map the Domain Admins group to a Unix group with net groupmap; otherwise, join with root (after smbpasswd -a root).

Firewall: only what the domain needs

The PDC sits on the internal bridge, the Windows client on the LAN. On the Proxmox host, the forward chain lets exactly the NetBIOS and SMB ports through, from the LAN, to that single container, and drops everything else going into vmbr1:

/etc/nftables.conf · forward chain (excerpt)
# NT4 domain (Samba PDC 192.168.1.105) for Windows clients on vmbr0
iifname "vmbr0" oifname "vmbr1" ip saddr 192.168.2.0/24 ip daddr 192.168.1.105 udp dport { 137, 138 } accept
iifname "vmbr0" oifname "vmbr1" ip saddr 192.168.2.0/24 ip daddr 192.168.1.105 tcp dport { 139, 445 } accept

# everything else from the LAN into vmbr1 is dropped
iifname "vmbr0" oifname "vmbr1" drop

My first attempt used DNAT rules on the host (ports 139 and 445 forwarded to the container), like the rest of the homelab at the time. Routing with explicit forward rules turned out cleaner for a protocol that also relies on name services. The whole ruleset is explained in the nftables article.

The Windows side

Modern Windows expects Active Directory. To join an NT4-style domain, Windows 10 needs two registry values under HKLM\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters:

DomainCompatibilityMode    DWORD  1
DNSNameResolutionRequired  DWORD  0

Then System → Rename this PC (advanced) → Domain: TPNIS, credentials of a domain admin, reboot. The machine account appears on the Samba side, and a NIS user can log on to Windows with their Samba password. The home folder shows up as H:.

Checks

CheckHow
Config is validtestparm -s
Daemons listeningss -tulnp | grep -E ':(137|138|139|445)'
NIS users visible to Sambagetent passwd testnis on CT 105
Samba accountspdbedit -L
Shares as a usersmbclient //localhost/commun -U testnis
Machine joinedgetent passwd shows a NAME$ account in the 20000+ range

Pitfalls worth knowing

The NIS domain name is easy to typo

tp.nis and nis.tp look alike at 1 a.m. With the wrong one, ypbind binds to nothing and Samba sees no users. Check with domainname and ypwhich before suspecting Samba.

Two passwords per user

Changing a password with yppasswd does not change the Windows one, and vice versa. That is the price of a classic PDC on top of NIS; LDAP-backed Samba (ldapsam) or Active Directory solve it with one store.

Windows hides the real error

"The specified domain either does not exist or could not be contacted" covers name resolution, SMB version, firewall and registry settings at once. Test each layer from the client: ping, nbtstat -a 192.168.1.105, net view \\192.168.1.105.

What I took away

Getting Windows to log on against accounts that live in a Linux NIS map, through a firewall that only opens four ports, covers a lot of ground: name resolution, authentication, file permissions and routing between bridges. It also made it very clear why companies moved to Active Directory and LDAP, which is where the next lab goes.