Windows and Linux Integration Series 2: DNS, Time Sync, Hostnames and Firewall Ports Before an Active Directory Join

Windows and Linux Integration Series, part 2. Previous: part 1, Overview and Choosing an Approach. This part covers the prerequisites that decide whether the first join works: DNS, time, host names and firewall ports. Next up: Kerberos as used with Active Directory (part 3).

Almost every failed Active Directory join from a Linux or Solaris host is not a Samba, SSSD or realmd problem. It is a DNS answer that came back wrong, a clock that is eight minutes off, a host name AD cannot make sense of, or a firewall that quietly drops one port. Fix those four things first and realm discover works on the first try, realm join just works, and the later posts on SSSD, Winbind, sudo, automount and kerberized NFS stand on solid ground.

This post applies to AlmaLinux, RHEL, Rocky Linux, Oracle Linux and CentOS Stream 8, 9 and 10, to Solaris 10 and Solaris 11.4 (a short section near the end), and to Active Directory domain controllers on Windows Server 2016, 2019, 2022 and 2025. The lab is the one from part 1: domain corp.example.com, realm CORP.EXAMPLE.COM, domain controllers dc1 (192.168.10.10) and dc2 (192.168.10.11), and the AlmaLinux test host rhel1.corp.example.com (192.168.10.20).

Prerequisites

  • Root or sudo on the Unix host, and a console or out-of-band access. A DNS change on a remote host can lock you out of it.
  • The IP addresses of at least two DCs that are also DNS servers for the AD zone.
  • Someone who can look at the Windows side: w32tm on a DC, the DNS zone for corp.example.com, and the firewall between the VLANs.
  • A host name decision: the fully qualified name the host will have in AD DNS, and a computer account name of 15 characters or fewer.

Step 1: Point the host at Active Directory DNS

AD is found through DNS. When you ask for corp.example.com, the client does not know any DC addresses; it queries SRV records such as _ldap._tcp.dc._msdcs.corp.example.com and gets back the list of DCs, their ports and their priorities. Only the AD-integrated DNS servers (normally the DCs themselves) have those records, so the Unix host must use them for its DNS.

Set the DNS servers and search domain with NetworkManager

On the RHEL family, NetworkManager owns /etc/resolv.conf. Change the connection, not the file, or your edit disappears at the next reconnect. Find the connection name first:

[root@rhel1 ~]# nmcli -t -f NAME,DEVICE connection show --active
System eth0:eth0
[root@rhel1 ~]# nmcli connection modify "System eth0" ipv4.dns "192.168.10.10 192.168.10.11" ipv4.dns-search "corp.example.com" ipv4.ignore-auto-dns yes
[root@rhel1 ~]# nmcli connection up "System eth0"
[root@rhel1 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search corp.example.com
nameserver 192.168.10.10
nameserver 192.168.10.11

The connection name is often System eth0, ens192 or Wired connection 1, so use what nmcli prints. The same commands appear in my older post on configuring a network connection on Oracle Linux. ipv4.ignore-auto-dns yes stops DHCP from adding other resolvers. Use ipv6.dns as well if the host has IPv6 DNS. If the host is DHCP-managed, the better fix is to have DHCP hand out the DC addresses and the corp.example.com search suffix.

Do not mix AD DNS with public DNS in resolv.conf. A resolver list of 192.168.10.10 followed by 8.8.8.8 works until the first DC answer is slow, then the client asks the public server, gets NXDOMAIN for _ldap._tcp.dc._msdcs.corp.example.com, and the join fails intermittently. Let the DCs forward public names (they have forwarders or root hints), or use a conditional forward on your corporate resolvers.

Test the SRV records the join depends on

dig comes from bind-utils on the RHEL family (dnf install bind-utils). These four lookups are the ones SSSD, realmd, adcli and Winbind use:

[root@rhel1 ~]# dig +short -t SRV _ldap._tcp.dc._msdcs.corp.example.com
0 100 389 dc1.corp.example.com.
0 100 389 dc2.corp.example.com.
[root@rhel1 ~]# dig +short -t SRV _kerberos._tcp.corp.example.com
0 100 88 dc1.corp.example.com.
0 100 88 dc2.corp.example.com.
[root@rhel1 ~]# dig +short -t SRV _kpasswd._tcp.corp.example.com
0 100 464 dc1.corp.example.com.
0 100 464 dc2.corp.example.com.
[root@rhel1 ~]# dig +short -t SRV _ldap._tcp.gc._msdcs.corp.example.com
0 100 3268 dc1.corp.example.com.
0 100 3268 dc2.corp.example.com.

Each answer is priority weight port target. If any of these return nothing, stop. The usual causes are: the host is not using AD DNS, the zone is a stub or secondary without the _msdcs subdomain, or a DC has not registered its records (on the DC, nltest /dsgetdc:corp.example.com and restarting the Netlogon service re-registers them). Also check that the targets resolve, because an SRV answer pointing at a name the client cannot resolve is as bad as no answer:

[root@rhel1 ~]# dig +short dc1.corp.example.com
192.168.10.10
[root@rhel1 ~]# dig +short -x 192.168.10.10
dc1.corp.example.com.

AD sites and subnets

Clients prefer DCs in their own AD site. Active Directory decides the site from the client’s IP address, using the subnets defined in Active Directory Sites and Services. If the Unix host’s subnet is not defined there, it lands in no site, and may pick a DC in another data center across a slow link. Ask the AD team to add the subnet. You can see the site-specific SRV records with dig +short -t SRV _ldap._tcp.Default-First-Site-Name._sites.dc._msdcs.corp.example.com, with your site name in place of Default-First-Site-Name. My older post on finding the domain controller you authenticate with shows how to find out which DC a host is actually using.

Step 2: Set the host name the way AD will see it

The host name becomes the computer account and the Kerberos service principal names: host/rhel1.corp.example.com and the short NetBIOS name RHEL1$. Set it before the join, because changing it afterwards means rebuilding the account and keytab.

[root@rhel1 ~]# hostnamectl set-hostname rhel1.corp.example.com
[root@rhel1 ~]# hostname
rhel1.corp.example.com
[root@rhel1 ~]# hostname -s
rhel1
[root@rhel1 ~]# grep -v '^#' /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.20 rhel1.corp.example.com rhel1
  • Use a fully qualified name under the AD DNS domain (or a DNS suffix the domain knows about). localhost.localdomain is the classic mistake on a fresh install.
  • Keep the NetBIOS name to 15 characters. The computer account (sAMAccountName) is the host name up to the first dot, and NetBIOS limits it to 15 characters. If your naming scheme is longer, set the account name yourself at join time (realm join --computer-name=RHEL1 ... or adcli join --computer-name=RHEL1 ...) so you know what AD calls the host, and make sure two hosts do not truncate to the same name.
  • Letters, digits and hyphens only. Underscores in names cause trouble with DNS and Kerberos.
  • One name for the host. The name in /etc/hosts, DNS A record, PTR record and hostname output should all agree.

A and PTR records, and dynamic DNS

With a correct A and PTR record, Kerberos can canonicalize the host name without surprises. SSSD’s AD provider updates the host’s A and PTR records in AD DNS on its own after the join (the dyndns_update option, enabled by default), if the zone accepts secure dynamic updates. If your DNS team prefers static records or the zone is not AD-integrated, create them by hand before the join and set dyndns_update = false in sssd.conf after it. Verify both directions:

[root@rhel1 ~]# dig +short rhel1.corp.example.com
192.168.10.20
[root@rhel1 ~]# dig +short -x 192.168.10.20
rhel1.corp.example.com.

If you cannot get reverse records, the Kerberos library can be told not to do reverse lookups by setting rdns = false under [libdefaults] in /etc/krb5.conf (or a file under /etc/krb5.conf.d/). Look at what is already configured on your release first, and fix the missing PTR record when you can; it is the better answer.

Step 3: Synchronize time with the domain

Kerberos protects against replayed tickets by embedding a timestamp, and a server rejects any request whose clock differs from its own by more than the allowed skew. The Active Directory default for Maximum tolerance for computer clock synchronization is five minutes, and MIT Kerberos clients default to 300 seconds as well. Past that you get Clock skew too great, and it looks exactly like a wrong password. Time is part of the prerequisites for the join, not a nicety.

How time flows in Active Directory

  • Domain members use the Windows Time service (w32time) in the NT5DS mode, and sync from a DC in their domain.
  • DCs sync from the domain’s PDC emulator. Child domains sync from the parent.
  • The PDC emulator of the forest root domain is the top of the hierarchy. It should be configured to sync from a reliable external source (a hardware clock, or public or internal NTP servers). If it is not, every DC and every Unix host agrees on a time that is wrong in the same way, which is harmless for Kerberos but terrible for logs.

So the goal for a Linux host is simple: agree with the DCs. The easiest way is to use the DCs as the host’s NTP servers. Windows DCs answer ordinary NTP requests from non-domain clients, and chrony works against them without any extra configuration.

Configure chrony on the Linux host

AlmaLinux, RHEL, Rocky Linux, Oracle Linux and CentOS Stream 8 and later use chronyd by default (the old ntpd package was removed in RHEL 8). Edit /etc/chrony.conf to use the DCs in place of the default pool:

[root@rhel1 ~]# dnf install -y chrony
[root@rhel1 ~]# grep -v -E '^(#|$)' /etc/chrony.conf
server dc1.corp.example.com iburst
server dc2.corp.example.com iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
keyfile /etc/chrony.keys
leapsectz right/UTC
logdir /var/log/chrony
[root@rhel1 ~]# systemctl enable --now chronyd
[root@rhel1 ~]# chronyc makestep
200 OK
  • Delete or comment out the pool or server lines for the public pool that were there before. Mixing sources works technically, but the Unix hosts should not follow a different clock than the domain.
  • makestep 1.0 3 lets chrony step the clock (instead of slewing) if the offset is over one second during the first three updates after start. That is what you want on a host that just booted with a wrong clock. chronyc makestep forces a step now.
  • If you prefer the Unix hosts to follow the same upstream as the PDC emulator, point them at those same servers instead. The DCs are simply the most convenient and most correct choice, because the DCs are what Kerberos compares you to.
[root@rhel1 ~]# chronyc sources -v
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* dc1.corp.example.com          3   6   377    21   +312us[ +420us] +/-   38ms
^+ dc2.corp.example.com          3   6   377    19   -118us[ -118us] +/-   41ms
[root@rhel1 ~]# chronyc tracking | grep -E 'Reference ID|System time|Leap status'
Reference ID    : C0A80A0A (dc1.corp.example.com)
System time     : 0.000000312 seconds fast of NTP time
Leap status     : Normal
[root@rhel1 ~]# timedatectl | grep -E 'System clock synchronized|NTP service'
System clock synchronized: yes
              NTP service: active

In chronyc sources, * marks the source in use and + a good candidate. Reach 377 means the last eight polls all worked. A ? or a Reach of 0 means the source is unreachable: check UDP 123 to the DC.

Check the Windows side

On a DC, in an elevated prompt, find the PDC emulator and see where it gets time. These are standard Windows tools, shown for the lab names:

C:\> netdom query fsmo
...
PDC                  dc1.corp.example.com
...
C:\> w32tm /query /source
time.windows.com,0x8
C:\> w32tm /query /status
Leap Indicator: 0(no warning)
Stratum: 3 (secondary reference - syncd by (S)NTP)
Source: time.windows.com,0x8
C:\> w32tm /monitor

If the forest root PDC emulator says Local CMOS Clock or Free-running System Clock, it has no external source. The usual fix, run on the PDC emulator only, is:

C:\> w32tm /config /manualpeerlist:"0.pool.ntp.org,0x8 1.pool.ntp.org,0x8" /syncfromflags:manual /reliable:yes /update
C:\> net stop w32time && net start w32time
C:\> w32tm /resync

Use your own NTP servers if policy requires it. Do not run that command on member servers or ordinary DCs; they should keep following the domain hierarchy.

Virtual machines

A virtual machine has two clocks fighting for control: the guest’s NTP daemon and the hypervisor’s time integration (VMware Tools time sync, Hyper-V time synchronization, KVM kvm-clock). For domain controllers especially, the guidance is to let the domain hierarchy win and turn the host time sync off, apart from the one-time sync at boot or resume. For Linux guests, run chrony and make sure the hypervisor integration does not step the clock behind its back. Check chronyc tracking for a steady offset, and watch for sudden jumps after a vMotion or snapshot restore.

Step 4: Open the firewall ports

Most of this traffic goes from the Unix host to the DCs, so a default firewalld configuration on the Linux host is fine: outbound connections are allowed. The ports that matter are on the network between the VLANs, and on the DCs. Red Hat documents these ports for direct integration using SSSD:

ServicePortProtocolUsed for
DNS53UDP and TCPSRV discovery, A and PTR lookups, dynamic updates
Kerberos88UDP and TCPTickets (kinit, SSH and service logins)
Kerberos password change464UDP and TCPkpasswd, and the machine account password at join
LDAP389UDP and TCPDirectory queries over TCP; UDP 389 carries the CLDAP “ping” used to find the closest DC
Global Catalog3268TCPForest-wide searches. Needed with id_provider = ad
SMB445TCP (UDP listed by Red Hat)Group Policy (GPO) access control, and Samba
LDAPS636TCPOptional: LDAP over TLS
LDAPS Global Catalog3269TCPOptional
NTP123UDPTime from the DCs

For the Samba and Winbind member role used later in this series, expect more: TCP 135 (the RPC endpoint mapper) and the dynamic RPC range, TCP 49152 to 65535 on current Windows Server, in addition to 445. SMB on 445 carries most of the Winbind traffic, but when 135 or the RPC range is blocked, some Winbind and net ads operations fail in ways that look like random authentication errors. If your firewall team cannot open the dynamic range, say so now, because it determines whether Winbind is an option on that VLAN. NetBIOS (UDP 137 and 138, TCP 139) is not needed for a modern AD with name resolution in DNS.

Test the TCP ports from the Linux host

This small script (which I ran against a local test listener to make sure the loop and the timeout behave) uses only bash and reports every TCP port in the table:

#!/bin/bash
# portcheck.sh - TCP reachability of the AD ports from this host
DC=${1:?usage: $0 dc-fqdn}
for p in 53 88 135 389 445 464 636 3268 3269; do
  if timeout 3 bash -c "exec 3<>/dev/tcp/$DC/$p" 2>/dev/null; then printf '%-5s open\n' $p; else printf '%-5s CLOSED or filtered\n' $p; fi
done
[root@rhel1 ~]# bash portcheck.sh dc1.corp.example.com
53    open
88    open
135   open
389   open
445   open
464   open
636   open
3268  open
3269  open

If 636 and 3269 are closed, LDAPS is simply not enabled on that DC, which is fine for now. A closed 88, 389, 445 or 464 is a firewall problem. This script only tests TCP. UDP cannot be verified reliably with a connect test, because a closed UDP port and a filtered one look the same. UDP 389 (the CLDAP ping), UDP 88 and UDP 123 are checked indirectly by realm discover and chronyc sources in the next steps.

The last check: realm discover

With DNS, host name, time and ports in place, realm discover should see the domain. The -v option prints the discovery steps, which is the first thing to read when it fails:

[root@rhel1 ~]# dnf install -y realmd adcli sssd oddjob oddjob-mkhomedir samba-common-tools krb5-workstation
[root@rhel1 ~]# realm discover -v corp.example.com
 * Resolving: _ldap._tcp.corp.example.com
 * Performing LDAP DSE lookup on: 192.168.10.10
 * Performing LDAP DSE lookup on: 192.168.10.11
 * Successfully discovered: corp.example.com
corp.example.com
  type: kerberos
  realm-name: CORP.EXAMPLE.COM
  domain-name: corp.example.com
  configured: no
  server-software: active-directory
  client-software: sssd
  required-package: oddjob
  required-package: oddjob-mkhomedir
  required-package: sssd
  required-package: adcli
  required-package: samba-common-tools

configured: no is correct at this point. The join itself comes in part 7. You can also confirm the Kerberos side with kinit as an AD user and klist; the client side of Kerberos is in my Kerberos client post (that one talks to an MIT KDC, but the client configuration is the same), and part 3 of this series covers how AD changes things.

Solaris 10 and Solaris 11.4

The same four prerequisites apply, with different tools. These steps are the DNS client and NTP only; the AD join for Solaris comes later in the series.

# Solaris 11.4: DNS client
solaris# svccfg -s network/dns/client setprop config/nameserver = net_address: "(192.168.10.10 192.168.10.11)"
solaris# svccfg -s network/dns/client setprop config/search = astring: corp.example.com
solaris# svccfg -s name-service/switch setprop config/host = astring: "files dns"
solaris# svcadm refresh name-service/switch network/dns/client
solaris# svcadm enable network/dns/client
solaris# nslookup -type=SRV _ldap._tcp.dc._msdcs.corp.example.com

# Solaris 11.4 and 10: time from the DCs
solaris# grep ^server /etc/inet/ntp.conf
server dc1.corp.example.com prefer
server dc2.corp.example.com
solaris# svcadm enable ntp       # or svcadm restart ntp
solaris# ntpq -p
  • Solaris 10 uses plain files: /etc/resolv.conf (nameserver and search lines), hosts: files dns in /etc/nsswitch.conf, and /etc/inet/ntp.conf (copy ntp.client to ntp.conf for a basic client), then svcadm enable ntp.
  • Solaris 11.4 keeps DNS and name switch settings in SMF properties. Change them with svccfg as above and refresh the services, and do not hand-edit /etc/resolv.conf, which is generated.
  • Set the host name before the join (svccfg -s system/identity:node setprop config/nodename = astring: sol11 on 11.4, /etc/nodename on 10) and keep it to 15 characters or fewer for the computer account.
  • Use ntpq -p (an asterisk marks the selected peer) to check synchronization.

Pros and cons of the choices in this post

ChoiceProsCons
Use AD DNS servers directly in resolv.confSimplest; SRV discovery just works; follows the AD site topologyEvery lookup depends on the DCs; public names need DC forwarders; a DNS outage on the DCs affects the Unix hosts
Conditional forwarder or _msdcs delegation on corporate DNSUnix hosts keep the standard resolvers; AD names resolve through forwardingAnother layer to maintain; SRV answers can go stale if forwarders are misconfigured; harder to debug
Static /etc/hosts and fixed DC namesWorks with no DNS access; explicitDefeats site awareness and failover; breaks when a DC is replaced; not something to run in production
chrony pointed at the DCsSame clock as Kerberos; one config; no external dependency for the hostIf the PDC emulator is wrong, you agree with its error; DCs need UDP 123 reachable from the Unix VLAN
chrony pointed at the same external NTP servers as the PDC emulatorIndependent of the DCs; good logsTwo paths to the same truth; if they diverge, Kerberos is the first thing that breaks
Open the full RPC range for WinbindWinbind and net ads work fullyLarge firewall opening; many security teams push back; SSSD does not need it

Verification checklist

  1. dig +short -t SRV _ldap._tcp.dc._msdcs.corp.example.com returns every DC, and the targets resolve.
  2. The host’s A and PTR records exist and match hostname.
  3. chronyc tracking shows an offset well under a second, and chronyc sources has a * next to a DC.
  4. bash portcheck.sh dc1.corp.example.com shows 53, 88, 389, 445, 464 and 3268 open, plus 135 if you plan to use Winbind.
  5. realm discover -v corp.example.com ends with “Successfully discovered” and server-software: active-directory.

Troubleshooting

SymptomCause and fix
realm discover prints nothing, or “No such realm found”DNS. The host is not using the DC resolvers, or the SRV lookup returns nothing. Run the dig -t SRV tests and fix them first.
Works sometimes, fails sometimesA public resolver mixed into resolv.conf, or one DC down and the client trying it first. Remove non-AD resolvers, and check both DCs answer.
kinit: Clock skew too great while getting initial credentialsTime. Check chronyc tracking, step the clock with chronyc makestep, and check the DC and VM time sync as above.
kinit: Cannot contact any KDC for realmThe KDC is unreachable on TCP or UDP 88, or the SRV lookup for _kerberos._tcp fails. Test both.
realm join fails with a DNS update or “Couldn’t resolve” errorThe A or PTR record is missing, the host name is not fully qualified, or the zone refuses secure dynamic updates. Create the records and retry.
Join works but users resolve slowly or pick a far DCThe client subnet is not assigned to an AD site. Ask for it.
Joins work from some VLANs onlyA firewall rule is missing 464, 3268 or UDP 389 on the failing path. Use the port script from that VLAN.
Computer account name differs from the host nameThe name was longer than 15 characters or set with --computer-name. Check realm list and the account in AD.
Time keeps jumping backTwo time sources fighting: chrony and the hypervisor, or two NTP daemons. Keep exactly one.

What was tested

I tested the portcheck.sh script on a Debian system against a local listener and a closed port, to confirm that the loop, the timeout and the open and closed reporting work. I did not run the rest of this post against a live Active Directory forest, so the dig, chronyc, realm discover and Windows w32tm output is representative sample output for the lab, not a captured transcript. The commands and options follow the Red Hat Enterprise Linux 9 documentation on direct integration with Active Directory using SSSD (which lists the required ports), the Microsoft documentation on Kerberos clock tolerance and the AD time hierarchy, and the chrony, realmd and NetworkManager manual pages. The Solaris SMF commands follow the Solaris documentation and were not run here. Test every step on a lab host before it goes anywhere near production.

Windows and Linux Integration Series: this is part 2. Previous: part 1, Overview and Choosing an Approach. Next up: part 3, Kerberos as used with Active Directory: tickets, SPNs, keytabs and the five-minute clock skew, then part 4 on preparing AD for Unix clients and part 5 on POSIX attributes (RFC2307). Related older posts: Join CentOS/RedHat to Active Directory Domain, Moving Windows NTP Server and the MIT Kerberos series starting with Set Up an MIT Kerberos KDC on AlmaLinux 10.

References: Red Hat Enterprise Linux 9 Connecting RHEL systems directly to AD using SSSD (including the ports table); Microsoft Learn Maximum tolerance for computer clock synchronization and Configure W32Time against huge time offset; the chrony.conf(5), nmcli(1), realm(8) and sssd-ad(5) manual pages.

Leave a Reply

Your email address will not be published. Required fields are marked *