Hier zeige ich dir, wie du einen Freeradius-Server so einrichtest, dass er mit einem Active Directory (AD) zur Authentifizierung zusammenarbeitet. Mit dieser Konfiguration ist Folgendes möglich:

  • Unterscheidung zwischen LAN und WLAN: Der Server erkennt, ob die Authentifizierung über ein kabelgebundenes Netzwerk (LAN) oder ein drahtloses Netzwerk (WLAN) erfolgt.
  • MAC-Authentifizierung im LAN: Bei einer Authentifizierung im LAN wird die MAC-Adresse des Geräts mit der Users-Datei abgeglichen.
  • LDAP- und MAC-Authentifizierung im WLAN: Für WLAN erfolgt die Authentifizierung über LDAP. Zusätzlich wird geprüft, ob die MAC-Adresse des Geräts in der Users-Datei für die verwendete SSID erlaubt ist.

Diese Anleitung basiert auf einem HP Switch und Aruba Access Points, die separat konfiguriert werden müssen.

Systemvoraussetzungen

  • Betriebssystem: Debian 12
  • Softwareversionen:
    • Freeradius 3.0
    • Samba 4.x
  • AD-Domain: Beispiel: STANGNETH / stangneth.com

Vorbereitung

Installation der Pakete

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
apt update
apt install freeradius freeradius-utils samba winbind libpam-winbind libnss-winbind
apt update apt install freeradius freeradius-utils samba winbind libpam-winbind libnss-winbind
apt update
apt install freeradius freeradius-utils samba winbind libpam-winbind libnss-winbind

Beitritt zur AD-Domain

Bearbeiten der /etc/samba/smb.conf:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[global]
workgroup = STANGNETH
security = ADS
realm = STANGNETH.COM
winbind use default domain = yes
winbind offline logon = yes
idmap config * : backend = tdb
idmap config * : range = 3000-7999
idmap config STANGNETH : backend = rid
idmap config STANGNETH : range = 10000-99999
template shell = /bin/bash
template homedir = /home/%U
kerberos method = secrets and keytab
log file = /var/log/samba/%m.log
log level = 1
[global] workgroup = STANGNETH security = ADS realm = STANGNETH.COM winbind use default domain = yes winbind offline logon = yes idmap config * : backend = tdb idmap config * : range = 3000-7999 idmap config STANGNETH : backend = rid idmap config STANGNETH : range = 10000-99999 template shell = /bin/bash template homedir = /home/%U kerberos method = secrets and keytab log file = /var/log/samba/%m.log log level = 1
[global]
   workgroup = STANGNETH
   security = ADS
   realm = STANGNETH.COM
   winbind use default domain = yes
   winbind offline logon = yes
   idmap config * : backend = tdb
   idmap config * : range = 3000-7999
   idmap config STANGNETH : backend = rid
   idmap config STANGNETH : range = 10000-99999
   template shell = /bin/bash
   template homedir = /home/%U
   kerberos method = secrets and keytab
   log file = /var/log/samba/%m.log
   log level = 1

Die Domain joinen:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
net ads join -U admin
net ads join -U admin
net ads join -U admin

Überprüfen, ob der Beitritt erfolgreich war:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
net ads testjoin
Join is OK
net ads testjoin Join is OK
net ads testjoin
Join is OK

Konfiguration von Freeradius

Module aktivieren

Sorge dafür, dass die notwendigen Module aktiviert sind. Dafür legst du symbolische Links in /etc/freeradius/3.0/mods-enabled/ an:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ln -s ../mods-available/mschap
ln -s ../mods-available/ntlm_auth
ln -s ../mods-available/eap
ln -s ../mods-available/ldap
ln -s ../mods-available/mschap ln -s ../mods-available/ntlm_auth ln -s ../mods-available/eap ln -s ../mods-available/ldap
ln -s ../mods-available/mschap
ln -s ../mods-available/ntlm_auth
ln -s ../mods-available/eap
ln -s ../mods-available/ldap

Modul eap anpassen

In der Datei /etc/freeradius/3.0/mods-enabled/eap passt du die Einstellungen für EAP an:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
eap {
default_eap_type = peap
peap {
ssl {
dh_file = /etc/freeradius/3.0/certs/dh
certificate_file = /etc/freeradius/3.0/certs/server.pem
private_key_file = /etc/freeradius/3.0/certs/server.key
}
use_tunneled_reply = yes
}
}
eap { default_eap_type = peap peap { ssl { dh_file = /etc/freeradius/3.0/certs/dh certificate_file = /etc/freeradius/3.0/certs/server.pem private_key_file = /etc/freeradius/3.0/certs/server.key } use_tunneled_reply = yes } }
eap {
  default_eap_type = peap
  peap {
    ssl {
      dh_file = /etc/freeradius/3.0/certs/dh
      certificate_file = /etc/freeradius/3.0/certs/server.pem
      private_key_file = /etc/freeradius/3.0/certs/server.key
    }
    use_tunneled_reply = yes
  }
}

Modul ntlm_auth anpassen

In /etc/freeradius/3.0/mods-enabled/ntlm_auth:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ntlm_auth {
ntlm_auth = "/usr/bin/ntlm_auth --request-nt-key --domain=%{mschap:NT-Domain} --username=%{mschap:User-Name} --password=%{User-Password}"
}
ntlm_auth { ntlm_auth = "/usr/bin/ntlm_auth --request-nt-key --domain=%{mschap:NT-Domain} --username=%{mschap:User-Name} --password=%{User-Password}" }
ntlm_auth {
  ntlm_auth = "/usr/bin/ntlm_auth --request-nt-key --domain=%{mschap:NT-Domain} --username=%{mschap:User-Name} --password=%{User-Password}"
}

Modul ldap anpassen

In /etc/freeradius/3.0/mods-enabled/ldap:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ldap {
server = "ldaps://dc.stangneth.com"
identity = "cn=radius,dc=stangneth,dc=com"
password = "Str0ngSecre3t!"
base_dn = "dc=stangneth,dc=com"
filter = "(sAMAccountName=%{Stripped-User-Name:-%{User-Name}})"
start_tls = yes
tls {
ca_file = /etc/freeradius/3.0/certs/ca.pem
}
}
ldap { server = "ldaps://dc.stangneth.com" identity = "cn=radius,dc=stangneth,dc=com" password = "Str0ngSecre3t!" base_dn = "dc=stangneth,dc=com" filter = "(sAMAccountName=%{Stripped-User-Name:-%{User-Name}})" start_tls = yes tls { ca_file = /etc/freeradius/3.0/certs/ca.pem } }
ldap {
  server = "ldaps://dc.stangneth.com"
  identity = "cn=radius,dc=stangneth,dc=com"
  password = "Str0ngSecre3t!"
  base_dn = "dc=stangneth,dc=com"
  filter = "(sAMAccountName=%{Stripped-User-Name:-%{User-Name}})"
  start_tls = yes
  tls {
    ca_file = /etc/freeradius/3.0/certs/ca.pem
  }
}

Proxy-Konfiguration

In der Datei /etc/freeradius/3.0/proxy.conf fügst du die Realms hinzu, um die integrierte Windows-Authentifizierung zu ermöglichen:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
realm stangneth.com {
type = radius
authhost = LOCAL
accthost = LOCAL
}
realm STANGNETH {
type = radius
authhost = LOCAL
accthost = LOCAL
}
realm stangneth.com { type = radius authhost = LOCAL accthost = LOCAL } realm STANGNETH { type = radius authhost = LOCAL accthost = LOCAL }
realm stangneth.com {
    type = radius
    authhost = LOCAL
    accthost = LOCAL
}

realm STANGNETH {
    type = radius
    authhost = LOCAL
    accthost = LOCAL
}

default-Datei erweitern

Die Datei /etc/freeradius/3.0/sites-enabled/default enthält einige wichtige Regeln. Hier ein Beispiel für WLAN- und LAN-Unterscheidung mit Abfrage der MAC aus der users Datei im authorize { } Block:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
if (&Service-Type == Login-User) {
files
}
if (&NAS-Port-Type == "Wireless-802.11") {
-ldap
if ((ok || updated) && User-Password && !control:Auth-Type) {
update control {
&Auth-Type := ldap
}
}
}
if (!&Service-Type == Login-User) {
rewrite_calling_station_id
if (&Calling-Station-Id) {
update request {
User-Name := "%{Calling-Station-Id}"
}
}
files
if (&reply:Allowed-SSIDs) {
update control {
Allowed-SSIDs := "%{reply:Allowed-SSIDs}"
}
}
if (&NAS-Port-Type != "Wireless-802.11") {
if (&reply:Tunnel-Private-Group-Id) {
update reply {
Tunnel-Type := VLAN
Tunnel-Medium-Type := IEEE-802
Tunnel-Private-Group-Id := "%{reply:Tunnel-Private-Group-Id}"
}
update control {
Auth-Type := Accept
}
} else {
update control {
Auth-Type := Accept
}
update reply {
Tunnel-Type := VLAN
Tunnel-Medium-Type := IEEE-802
Tunnel-Private-Group-Id := 666
}
update {
&Tmp-String-0 := "Fallback VLAN 666 wurde angewendet"
}
}
} else {
if (!&control:Allowed-SSIDs) {
reject
} else {
if (&Aruba-Essid-Name && &control:Allowed-SSIDs) {
if ("%{control:Allowed-SSIDs}" =~ /(^|[|])%{Aruba-Essid-Name}([|]|$)/) {
update control {
Auth-Type := Accept
}
} else {
reject
}
}
}
}
} else {
noop
}
if (&Service-Type == Login-User) { files } if (&NAS-Port-Type == "Wireless-802.11") { -ldap if ((ok || updated) && User-Password && !control:Auth-Type) { update control { &Auth-Type := ldap } } } if (!&Service-Type == Login-User) { rewrite_calling_station_id if (&Calling-Station-Id) { update request { User-Name := "%{Calling-Station-Id}" } } files if (&reply:Allowed-SSIDs) { update control { Allowed-SSIDs := "%{reply:Allowed-SSIDs}" } } if (&NAS-Port-Type != "Wireless-802.11") { if (&reply:Tunnel-Private-Group-Id) { update reply { Tunnel-Type := VLAN Tunnel-Medium-Type := IEEE-802 Tunnel-Private-Group-Id := "%{reply:Tunnel-Private-Group-Id}" } update control { Auth-Type := Accept } } else { update control { Auth-Type := Accept } update reply { Tunnel-Type := VLAN Tunnel-Medium-Type := IEEE-802 Tunnel-Private-Group-Id := 666 } update { &Tmp-String-0 := "Fallback VLAN 666 wurde angewendet" } } } else { if (!&control:Allowed-SSIDs) { reject } else { if (&Aruba-Essid-Name && &control:Allowed-SSIDs) { if ("%{control:Allowed-SSIDs}" =~ /(^|[|])%{Aruba-Essid-Name}([|]|$)/) { update control { Auth-Type := Accept } } else { reject } } } } } else { noop }
if (&Service-Type == Login-User) {
    files
}

if (&NAS-Port-Type == "Wireless-802.11") {
    -ldap
    if ((ok || updated) && User-Password && !control:Auth-Type) {
        update control {
            &Auth-Type := ldap
        }
    }
}

if (!&Service-Type == Login-User) {
    rewrite_calling_station_id

    if (&Calling-Station-Id) {
        update request {
            User-Name := "%{Calling-Station-Id}"
        }
    }

    files

    if (&reply:Allowed-SSIDs) {
        update control {
            Allowed-SSIDs := "%{reply:Allowed-SSIDs}"
        }
    }

    if (&NAS-Port-Type != "Wireless-802.11") {
        if (&reply:Tunnel-Private-Group-Id) {
            update reply {
                Tunnel-Type := VLAN
                Tunnel-Medium-Type := IEEE-802
                Tunnel-Private-Group-Id := "%{reply:Tunnel-Private-Group-Id}"
            }
            update control {
                Auth-Type := Accept
            }
        } else {
            update control {
                 Auth-Type := Accept
            }
            update reply {
                Tunnel-Type := VLAN
                Tunnel-Medium-Type := IEEE-802
                Tunnel-Private-Group-Id := 666
            }
            update {
                &Tmp-String-0 := "Fallback VLAN 666 wurde angewendet"
            }
        }
    } else {
        if (!&control:Allowed-SSIDs) {
            reject
        } else {
            if (&Aruba-Essid-Name && &control:Allowed-SSIDs) {
                if ("%{control:Allowed-SSIDs}" =~ /(^|[|])%{Aruba-Essid-Name}([|]|$)/) {
                    update control {
                        Auth-Type := Accept
                    }
                } else {
                    reject
                } 
            }
        }
    }
} else {
    noop
}

Dieser Abschnitt sorgt dafür, dass Nutzer je nach Netzwerkzugriff (LAN oder WLAN) unterschiedliche Authentifizierungsregeln durchlaufen.

Inner-Tunnel-Konfiguration

In der Datei /etc/freeradius/3.0/sites-enabled/inner-tunnel:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
server inner-tunnel {
authorize {
preprocess
mschap
}
authenticate {
Auth-Type MS-CHAP {
mschap
}
}
}
server inner-tunnel { authorize { preprocess mschap } authenticate { Auth-Type MS-CHAP { mschap } } }
server inner-tunnel {
  authorize {
    preprocess
    mschap
  }

  authenticate {
    Auth-Type MS-CHAP {
      mschap
    }
  }
}

Users-Datei anpassen

In /etc/freeradius/3.0/users fügst du eine strukturierte Users-Datei hinzu:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#########################################################
# FreeRADIUS Users-Datei
# Strukturierte Eintraege nach Kategorien:
# - VLAN-Zuweisungen fuerr kabelgebundene Geraete
# - WLAN-Zugriff basierend auf SSID
#########################################################
#########################################################
# VLAN-Zuweisungen fuer kabelgebundene Geraete (LAN)
#########################################################
# PC1
00:11:4B:04:8C:F7 Cleartext-Password := "00114b048cf7"
Tunnel-Type = VLAN,
Tunnel-Medium-Type = IEEE-802,
Tunnel-Private-Group-Id = 100
# PC2
38:EF:E3:0A:61:53 Cleartext-Password := "38efe30a6153"
Tunnel-Type = VLAN,
Tunnel-Medium-Type = IEEE-802,
Tunnel-Private-Group-Id = 200
#########################################################
# WLAN-Zugriff basierend auf SSID
#########################################################
# user1-lap
AC-84-B1-66-5A-DA Cleartext-Password := "ac84b1665ada"
Allowed-SSIDs := "SSID1"
# user2-lap
A0-02-C8-EB-DD-EF Cleartext-Password := "a002c8ebddef"
Allowed-SSIDs := "SSID1|SSID2"
#########################################################
# VLAN-Zuweisungen fuer Drucker (LAN)
#########################################################
# Drucker1
58:38:79:66:C2:1F Cleartext-Password := "58387966C21f"
Tunnel-Type = VLAN,
Tunnel-Medium-Type = IEEE-802,
Tunnel-Private-Group-Id = 300
######################################################### # FreeRADIUS Users-Datei # Strukturierte Eintraege nach Kategorien: # - VLAN-Zuweisungen fuerr kabelgebundene Geraete # - WLAN-Zugriff basierend auf SSID ######################################################### ######################################################### # VLAN-Zuweisungen fuer kabelgebundene Geraete (LAN) ######################################################### # PC1 00:11:4B:04:8C:F7 Cleartext-Password := "00114b048cf7" Tunnel-Type = VLAN, Tunnel-Medium-Type = IEEE-802, Tunnel-Private-Group-Id = 100 # PC2 38:EF:E3:0A:61:53 Cleartext-Password := "38efe30a6153" Tunnel-Type = VLAN, Tunnel-Medium-Type = IEEE-802, Tunnel-Private-Group-Id = 200 ######################################################### # WLAN-Zugriff basierend auf SSID ######################################################### # user1-lap AC-84-B1-66-5A-DA Cleartext-Password := "ac84b1665ada" Allowed-SSIDs := "SSID1" # user2-lap A0-02-C8-EB-DD-EF Cleartext-Password := "a002c8ebddef" Allowed-SSIDs := "SSID1|SSID2" ######################################################### # VLAN-Zuweisungen fuer Drucker (LAN) ######################################################### # Drucker1 58:38:79:66:C2:1F Cleartext-Password := "58387966C21f" Tunnel-Type = VLAN, Tunnel-Medium-Type = IEEE-802, Tunnel-Private-Group-Id = 300
#########################################################
# FreeRADIUS Users-Datei
# Strukturierte Eintraege nach Kategorien:
# - VLAN-Zuweisungen fuerr kabelgebundene Geraete
# - WLAN-Zugriff basierend auf SSID
#########################################################

#########################################################
# VLAN-Zuweisungen fuer kabelgebundene Geraete (LAN)
#########################################################

# PC1
00:11:4B:04:8C:F7  Cleartext-Password := "00114b048cf7"
    Tunnel-Type = VLAN,
    Tunnel-Medium-Type = IEEE-802,
    Tunnel-Private-Group-Id = 100
	
# PC2
38:EF:E3:0A:61:53  Cleartext-Password := "38efe30a6153"
    Tunnel-Type = VLAN,
    Tunnel-Medium-Type = IEEE-802,
    Tunnel-Private-Group-Id = 200

#########################################################
# WLAN-Zugriff basierend auf SSID
#########################################################

# user1-lap
AC-84-B1-66-5A-DA  Cleartext-Password := "ac84b1665ada"
    Allowed-SSIDs := "SSID1"

# user2-lap
A0-02-C8-EB-DD-EF  Cleartext-Password := "a002c8ebddef"
    Allowed-SSIDs := "SSID1|SSID2"

#########################################################
# VLAN-Zuweisungen fuer Drucker (LAN)
#########################################################

# Drucker1
58:38:79:66:C2:1F  Cleartext-Password := "58387966C21f"
    Tunnel-Type = VLAN,
    Tunnel-Medium-Type = IEEE-802,
    Tunnel-Private-Group-Id = 300

Berechtigungen setzen

Erstelle die Gruppe winbindd_privileged, falls sie nicht existiert:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
groupadd winbindd_privileged
usermod -aG winbindd_privileged freerad
groupadd winbindd_privileged usermod -aG winbindd_privileged freerad
groupadd winbindd_privileged
usermod -aG winbindd_privileged freerad

Setze die korrekten Berechtigungen für das Verzeichnis:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
mkdir -p /var/run/samba/winbindd_privileged
chown root:winbindd_privileged /var/run/samba/winbindd_privileged
chmod 750 /var/run/samba/winbindd_privileged
mkdir -p /var/run/samba/winbindd_privileged chown root:winbindd_privileged /var/run/samba/winbindd_privileged chmod 750 /var/run/samba/winbindd_privileged
mkdir -p /var/run/samba/winbindd_privileged
chown root:winbindd_privileged /var/run/samba/winbindd_privileged
chmod 750 /var/run/samba/winbindd_privileged

Starte Winbind neu:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
systemctl restart winbind
systemctl restart winbind
systemctl restart winbind

Fehlerbehebung

Debugging

Starte Freeradius im Debug-Modus:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
freeradius -X
freeradius -X
freeradius -X

Disclaimer

Diese Anleitung dient als Orientierung und sollte an die jeweilige Umgebung angepasst werden. Die Artikel sind ausschließlich zu Testzwecken gedacht, und ich übernehme keine Haftung für eventuelle Schäden oder Fehlfunktionen. Ich empfehle, jede Konfiguration gründlich zu prüfen und in einer sicheren Testumgebung auszuprobieren. Gerne stehe ich Ihnen für eine individuelle Beratung und Umsetzung zur Verfügung.