Menu bài viết
Trong bài hướng dẫn trước, An Ninh Mạng đã hướng dẫn bạn cách cài đặt cấu hình Samba server để chia sẻ file. Hôm nay mình sẽ tiếp tục hướng dẫn cách cài đặt Samba primary domain controller trong CentOS 7. Với hệ điều hành RHEL 7 và Scientific Linux 7, các bước thực hiện cũng tương tự .
Chuẩn bị :
Để làm bài lab, chúng ta chuẩn bị 2 máy :
Samba PDC:
OS: CentOS 7 Minimal server
Hostname: server.anninhmang.local
IP Address: 192.168.1.150/24
Samba Domain: ANNINHMANG
Client:
OS: Windows 7 32 bit
Hostname: mywindesktop
IP Address: 192.168.1.100/24
Chúng ta sẽ bắt đầu với phần cài đặt Samba primary domain controller.
Installation :
Chạy lệnh sau để cài đặt samba package :
yum install samba* -y
Để verify version của Samba, nhập vào lệnh sau :
smbd –V
smbclient –V
Kết quả trả về sẽ là :
Version 4.1.1
Cấu hình Samba :
Edit file cấu hình samba :
vi /etc/samba/smb.conf
Tìm đến những dòng sau, và thay đổi như bên dưới. Thay thế ANNINHMANG bằng tên domain của bạn :
[Global] workgroup = ANNINHMANG security = user domain master = yes domain logons = yes local master = yes preferred master = yes passdb backend = tdbsam logon path = \\%L\Profiles\%U logon script = logon.bat add machine script = /usr/sbin/useradd -d /dev/null -g 200 -s /sbin/nologin -M %u [homes] comment = Home Directories browseable = yes writable = yes [printers] comment = All Printers path = /var/spool/samba printable = Yes print ok = Yes browseable = No [netlogon] comment = Network Logon Service path = /var/lib/samba/netlogon browseable = No writable = No [Profiles] path = /var/lib/samba/profiles create mask = 0755 directory mask = 0755 writable = Yes
Nếu thấy hơi lằng nhằng, bạn có thể đơn giản di chuyển file smb.conf đến thư mục khác :
mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
Và tạo một file smb.conf mới trong thư mục /etc/samba/ :
vi /etc/samba/smb.conf
Và copy/ paste những dòng trên vào file. Đừng quên đổi đúng tên domain của bạn.
Lưu và đóng file lại.
Test lỗi file cấu hình Samba bằng lệnh :
testparm
Kết quả trả về của bạn sẽ là :
Load smb config files from /etc/samba/smb.conf rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) Processing section "[homes]" Processing section "[printers]" Processing section "[netlogon]" Processing section "[Profiles]" Loaded services file OK. Server role: ROLE_DOMAIN_PDC Press enter to see a dump of your service definitions [global] workgroup = ANNINHMANG add machine script = /usr/sbin/useradd -d /dev/null -g 200 -s /sbin/nologin -M %u logon script = logon.bat logon path = \\%L\Profiles\%U domain logons = Yes preferred master = Yes domain master = Yes idmap config * : backend = tdb [homes] comment = Home Directories read only = No [printers] comment = All Printers path = /var/spool/samba printable = Yes print ok = Yes browseable = No [netlogon] comment = Network Logon Service path = /var/lib/samba/netlogon browseable = No [Profiles] path = /var/lib/samba/profiles read only = No create mask = 0755
Tạo các thư mục share với quyền như chúng ta đã khai báo trong file smb.conf :
mkdir -m 1777 /var/lib/samba/netlogon mkdir -m 1777 /var/lib/samba/profiles
Tiếp theo, tạo user dùng để logon vào domain :
useradd user1 useradd user2
Tạo account machine :
Bạn cần phải tạo machine account cho mỗi máy tính muốn logon vào domain. Machine account là loại tài khoản account được quy định bằng kí hiệu $ cuối tên tài khoản ( VD : Machine$ ).
Tạo một tài khoản tên “machine” với group id “ 200 “ :
groupadd -g 200 machine
Để add Samba machine account, chạy dòng lệnh :
smbpasswd -m -a machine1$
Mục smbpasswd –m – cho biết tài khoản đó sẽ được sử dụng NT primary domain controller (Machine account).
Để tìm hiểu thêm về các loại smbpasswd, ta truy cập link này.
Tạo Samba user account :
smbpasswd -a root smbpasswd -a user1 smbpasswd -a user2
Trong đó, “root” là tài khoản admin có thể được dùng cho các hệ điều hành Windows NT/2000/XP/7/10 để gia nhập vào domain. Không nên đặt mật khẩu root smbpasswd giống với mật khẩu root sử dụng để đăng nhập vào server. Sử dùng mật khẩu root giống nhau làm tiềm ẩn nguy cơ tài khoản root có thể bị xâm nhập trái phép vào server.
Khởi chạy Samba service :
Cuối cùng ta start samba service và enable samba để tự động khởi chạy mỗi khi hệ thống boot :
systemctl start smb systemctl start nmb systemctl enable smb systemctl enable nmb
Cấu hình Firewall :
Samba sử dụng các port sau để chạy Active Directory Domain Controller:
Service | Port | protocol |
DNS | 53 | tcp/udp |
Kerberos | 88 | tcp/udp |
End Point Mapper (DCE/RPC Locator Service) | 135 | tcp |
NetBIOS Name Service | 137 | udp |
NetBIOS Datagram | 138 | udp |
NetBIOS Session | 139 | tcp |
LDAP | 389 | tcp/udp |
SMB over TCP | 445 | tcp |
Kerberos kpasswd | 464 | tcp/udp |
LDAPS (only if “tls enabled = yes”) | 636 | tcp |
Dynamic RPC Ports* | 1024-5000 | tcp |
Global Cataloge | 3268 | tcp |
Global Cataloge SSL (only if “tls enabled = yes”) | 3269 | tcp |
Multicast DNS | 5353 | tcp/udp |
Chạy lần lượt từng dòng lệnh sau để mở port Firewall cho Samba :
firewall-cmd --permanent --add-port=53/tcp firewall-cmd --permanent --add-port=53/udp firewall-cmd --permanent --add-port=88/tcp firewall-cmd --permanent --add-port=88/udp firewall-cmd --permanent --add-port=135/tcp firewall-cmd --permanent --add-port=137/tcp firewall-cmd --permanent --add-port=137/udp firewall-cmd --permanent --add-port=138/udp firewall-cmd --permanent --add-port=139/tcp firewall-cmd --permanent --add-port=389/tcp firewall-cmd --permanent --add-port=389/udp firewall-cmd --permanent --add-port=445/tcp firewall-cmd --permanent --add-port=464/tcp firewall-cmd --permanent --add-port=464/udp firewall-cmd --permanent --add-port=636/tcp firewall-cmd --permanent --add-port=1024-5000/tcp firewall-cmd --permanent --add-port=1024-5000/udp firewall-cmd --permanent --add-port=3268/tcp firewall-cmd --permanent --add-port=3269/tcp firewall-cmd --permanent --add-port=5353/tcp firewall-cmd --permanent --add-port=5353/udp
Cuối cùng restart lại firewall.
firewall-cmd –reload
Lưu ý nên disable SElinux để không bị chặn truy cập Samba. Nếu không muốn disable ta cần quy định rule cho SElinux. Áp SElinux policy cho Samba domain controller.
setsebool -P samba_domain_controller on setsebool -P samba_enable_home_dirs on
Áp vào thư mục samba share mà chúng ta đã định nghĩa trong file smb.conf :
chcon -t samba_share_t /var/lib/samba/netlogon chcon -t samba_share_t /var/lib/samba/profiles
Join windows client vào Samba DC :
Chúng ta sẽ thử join máy chạy Windows vào Samba Domain Controller bằng những user vừa tạo :
Right click vào My Computer, chọn Properties ->Advanced system settings.
Ở mục Computer Name, bấm vào nút Change.
Ở mục Domain, nhập vào Domain name. Ở bài viết này, ta nhập vào anninhmang.
Nhập vào tài khoản root và password samba của nó.
Có thể sẽ xuất hiện lỗi như sau :
"The specified domain either does not exist or could not be contacted"
Chúng ta có thể dễ dàng fix lỗi này bằng cách sau :
Mở registry, đến khóa HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Services -> LanmanWorkstation -> Parameters.
Tạo 2 giá trị DWORD tên “DomainCompatibilityMode” và “DNSNameResolutionRequired”. Set giá trị “DomainCompatibilityMode” là 1 và “DNSNameResolutionRequired” là 0. Như hình bên dưới :
Như vậy là chúng ta đã có thể Join máy Windows vào domain được.
Bấm Ok để tiếp tục. Có thể ở đây sẽ tiếp tục xuất hiện lỗi :
Changing the Primary Domain DNS name of this computer to "" failed. The name will remain "ANNINHMANG". The error was: The specified domain either does not exist or could not be contacted
Chúng ta chỉ cần bấm OK để bỏ qua cảnh báo này. Không cần restart lại.
Download và install hotfix tại link này để fix lỗi.
https://support.microsoft.com/kb/2171571
Sau khi install, restart lại máy client Windows và bạn có thể login vào Samba domain được.
Bấm tổ hợp phím CTRL+ALT+Del, Chọn Switch user, và chọn option Other user.
Nhập vào username và password. Trước đó chúng ta đã tạo 2 user là user1 và user2 :
Như vậy là chúng ta đã có thể Logon được vào domain.
Ngoài ra, một ổ cứng mạng cũng được tạo ra cho mỗi user. User có thể lưu trữ file/folder cá nhân của mình trong folder này.
Truy cập thử profile roaming từ máy windows của 2 user này trên Samba server :
ls /var/lib/samba/profiles
Sẽ thấy 2 thư mục :
user1.V2 user2.V2
Liệt kê thử nội dung thư mục user1.V2 :
ls /var/lib/samba/profiles/user1.V2/
Kết quả trả về :
AppData Desktop Downloads Links NTUSER.DAT Pictures Searches Contacts Documents Favorites Music ntuser.ini Saved Games Videos
Như vậy là chúng ta đã hoàn thành cấu hình Samba Domain Controller trên CentOS 7. Ta có thể bắt đầu sử dụng được rồi.