Samba4+BIND9_FLATFILEでの設定も試してみる。
BINDをインストールして、ntp、Samba、Kerberos をインストールするところまでは同じ。
Samba-tool provision で生成したファイルをBINDに組み込む部分が少し違う。
下ごしらえ
こちらも先の[samba] Ubuntu14.04でSamba4のまとめと重複するので、詳細な説明は省きます。
$ sudo apt-get update $ sudo apt-get upgrade
/etc/interfaces の編集
$ sudo vi /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.10.0
bloadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 192.168.1.100 8.8.8.8
dns-search mydomain.local
/etc/hostname の編集
/etc/hostnameでサーバホスト名を編集。
$ sudo vim /etc/hostname
pdc
/etc/hosts の編集
/etc/hosts の内容を次のように設定する。
127.0.0.1 localhost # 127.0.1.1 mydomain.local pdc # この行はコメントアウトします 192.168.10.141 mydomain.local pdc
再起動
ここで、さきに設定したネットワーク関連情報を反映させるために、再起動させる。
ntpサーバのインストール
NTPサーバをインストールする。
$ sudo apt-get install ntp
/etc/ntp.confの設定を変更する。
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board # on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for # more information. #server 0.ubuntu.pool.ntp.org #server 1.ubuntu.pool.ntp.org #server 2.ubuntu.pool.ntp.org #server 3.ubuntu.pool.ntp.org server ntp.nict.jp server ntp.nict.jp server ntp.nict.jp
一旦、NTPサービスを停止させて、時刻を合わせる。
$ sudo service ntp stop $ sudo ntpdate -B ntp.nict.jp
NTPサービスを再起動後、設定が有効になる。
$ sudo service ntp start
NTPとの同期の状態を確認
$ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+ntp-b3.nict.go. .NICT. 1 u 8 64 377 13.099 27.284 14.266
*ntp-b2.nict.go. .NICT. 1 u 5 64 377 13.238 51.113 17.961
/etc/fstabの編集
UUID=cXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX / ext4 user_xattr,acl,barrier=1,errors=remount-ro 0 1 ※UUIDにはそのHDD固有の番号がつきます。
ACLパッケージをインストール。
$ sudo apt-get install acl
その後、再起動し/etc/fstab の設定を反映させます。
BINDの設定
BINDのインストール
$ sudo apt-get install bind9
IPv6を無効にする
/etc/sysctl.confに以下を追加します。
net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1
追加したら、それを適用します。
$ sudo sysctl -p net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1
BINDの起動オプションも変更しておきます。
# run resolvconf? RESOLVCONF=no # startup options for the server OPTIONS="-u bind -4"
/etc/bind/named.conf
named.conf.default-zones は、別の場所でインクルードするので、コメントアウト。
// This is the primary configuration file for the BIND DNS server named. // // Please read /usr/share/doc/bind9/README.Debian.gz for information on the // structure of BIND configuration files in Debian, *BEFORE* you customize // this configuration file. // // If you are just adding zones, please do that in /etc/bind/named.conf.local include "/etc/bind/named.conf.options"; include "/etc/bind/named.conf.local"; # include "/etc/bind/named.conf.default-zones";
/etc/bind/named.conf.options
ここでも、IPv6を無効にするために、一番最後の方にある listen-on-v6{ any;}; を、
listen-on-v6{ none; };
にする。
acl localnet {
192.168.0.0/16; #VPNの複数のネットワークアドレスから接続可
127.0.0.1;
};
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.
listen-on port 53 {
localnet;
};
allow-query {
localnet;
};
allow-transfer {
localnet;
};
forwarders {
8.8.8.8; # プロバイダ等からの
X.Y.Z.A; # 指定されているDNS
};
//========================================================================
// If BIND logs error messages about the root key being expired,
// you will need to update your keys. See https://www.isc.org/bind-keys
//========================================================================
dnssec-validation no;
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { none; };
};
/etc/bind/named.conf.local
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
view "internal" {
include "/etc/bind/named.conf.default-zones";
match-clients {
localnet;
};
};
ゾーン設定の確認
BINDを再起動して、ゾーン設定が正しいかどうか以下のコマンドで確認します。
$ sudo /etc/init.d/bind9 restart $ host localhost. 127.0.0.1 Using domain server: Name: 127.0.0.1 Address: 127.0.0.1#53 Aliases: localhost has address 127.0.0.1
$ host 127.0.0.1 127.0.0.1 Using domain server: Name: 127.0.0.1 Address: 127.0.0.1#53 Aliases: 1.0.0.127.in-addr.arpa domain name pointer localhost.
Sambaのセットアップ
Sambaのインストール
samba4と、smbclient、krb5-userをインストール。
$ sudo apt-get install samba smbclient krb5-user
途中でkerberosの設定画面が出てきて、設定をするように促されますので、概ね以下のとおりに設定。
|
|
samba-toolでSambaの使用準備をする
まず、デフォルトで作成された設定ファイルを削除か、リネームします。
$ sudo rm /etc/samba/smb.conf
samba-tool で、sambaの基本的な設定をします。
ここでは、DNS backend = BIND9_FLATFILEとして進めていきます。また、この場合DNS forwarder IP Address は聞かれません。
$ sudo samba-tool domain provision --use-rfc2307 --interactive Realm: MYDOMAIN.LOCAL Domain [MYDOMAIN]: Server Role (dc, member, standalone) [dc]: DNS backend (SAMBA_INTERNAL, BIND9_FLATFILE, BIND9_DLZ, NONE) [SAMBA_INTERNAL]:BIND9_FLATFILE Administrator password: Retype password: [...] Server Role: active directory domain controller Hostname: pdc NetBIOS Domain: MYDOMAIN DNS Domain: mydomain.local DOMAIN SID: S-1-5-21-XXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX
ドメインのレベルを2008 R2相当に上げる
$ sudo samba-tool domain level raise --domain-level 2008_R2 --forest-level 2008_R2
krb5.confの差し替え
[libdefaults]
default_realm = MYDOMAIN.LOCAL
dns_lookup_realm = false
dns_lookup_kdc = true
[realms]
MYDOMAIN.LOCAL = {
kdc = pdc.mydomain.local
admin_server = pdc.mydomain.local
}
[domain_realm]
.mydomain.local = MYDOMAIN.LOCAL
mydomain.local = MYDOMAIN.LOCAL
Samba4+BIND9_FLATFILEを設定する
設定方法は、BIND9_DLZと微妙に異なります。ゾーン設定ファイルがテキストで見れるので、*nix使いの人からしてみれば、こちらのほうが親和性があるのかな?
/var/lib/samba/private/named.conf
このファイルは変更可能?
逆引きゾーン設定は自分で作成することができそう。
# This file should be included in your main BIND configuration file
#
# For example with
# include "/var/lib/samba/private/named.conf";
zone "mydomain.local." IN {
type master;
file "/var/lib/samba/private/dns/mydomain.local.zone";
/*
* the list of principals and what they can change is created
* dynamically by Samba, based on the membership of the domain controllers
* group. The provision just creates this file as an empty file.
*/
include "/var/lib/samba/private/named.conf.update";
/* we need to use check-names ignore so _msdcs A records can be created */
check-names ignore;
};
# The reverse zone configuration is optional. The following example assumes a
# subnet of 192.168.123.0/24:
/*
zone "123.168.192.in-addr.arpa" in {
type master;
file "123.168.192.in-addr.arpa.zone";
update-policy {
grant *.LOCAL wildcard *.123.168.192.in-addr.arpa. PTR;
};
};
*/
# Note that the reverse zone file is not created during the provision process.
# The most recent BIND versions (9.8 or later) support secure GSS-TSIG
# updates. If you are running an earlier version of BIND, or if you do not wish
# to use secure GSS-TSIG updates, you may remove the update-policy sections in
# both examples above.
/var/lib/samba/private/named.conf.update
このファイルにインクルードされているファイル。DO NOT EDIT ということです。
/* this file is auto-generated - do not edit */
update-policy {
grant MYDOMAIN.LOCAL ms-self * A AAAA;
grant Administrator@MYDOMAIN.LOCAL wildcard * A AAAA SRV CNAME;
grant pdc$@MYDOMAIN.local wildcard * A AAAA SRV CNAME;
};
/var/lib/samba/private/dns/mydomain.local.zone
ゾーン設定ファイル。
; -*- zone -*-
; generated by provision.pl
$ORIGIN mydomain.local.
$TTL 1W
@ IN SOA pdc hostmaster (
2015030316 ; serial
2D ; refresh
4H ; retry
6W ; expiry
1W ) ; minimum
IN NS pdc
IN A 192.168.10.141
;
pdc IN A 192.168.10.141
gc._msdcs IN A 192.168.10.141
5e866d19-074f-4056-bde3-7e2be4c727a5._msdcs IN CNAME pdc
;
; global catalog servers
_gc._tcp IN SRV 0 100 3268 pdc
_gc._tcp.Default-First-Site-Name._sites IN SRV 0 100 3268 pdc
_ldap._tcp.gc._msdcs IN SRV 0 100 3268 pdc
_ldap._tcp.Default-First-Site-Name._sites.gc._msdcs IN SRV 0 100 3268 pdc
;
; ldap servers
_ldap._tcp IN SRV 0 100 389 pdc
_ldap._tcp.dc._msdcs IN SRV 0 100 389 pdc
_ldap._tcp.pdc._msdcs IN SRV 0 100 389 pdc
_ldap._tcp.9837df53-9462-4170-a2cd-e56c10eab324.domains._msdcs IN SRV 0 100 389 pdc
_ldap._tcp.Default-First-Site-Name._sites IN SRV 0 100 389 pdc
_ldap._tcp.Default-First-Site-Name._sites.dc._msdcs IN SRV 0 100 389 pdc
;
; krb5 servers
_kerberos._tcp IN SRV 0 100 88 pdc
_kerberos._tcp.dc._msdcs IN SRV 0 100 88 pdc
_kerberos._tcp.Default-First-Site-Name._sites IN SRV 0 100 88 pdc
_kerberos._tcp.Default-First-Site-Name._sites.dc._msdcs IN SRV 0 100 88 pdc
_kerberos._udp IN SRV 0 100 88 pdc
; MIT kpasswd likes to lookup this name on password change
_kerberos-master._tcp IN SRV 0 100 88 pdc
_kerberos-master._udp IN SRV 0 100 88 pdc
;
; kpasswd
_kpasswd._tcp IN SRV 0 100 464 pdc
_kpasswd._udp IN SRV 0 100 464 pdc
;
; heimdal 'find realm for host' hack
_kerberos IN TXT MYDOMAIN.LOCAL
/etc/bind/named.conf.local
Provisioningを実行すると、/var/lib/samba/private 直下にDNS関連のファイルが生成されます。
その内の一つのファイル /var/lib/samba/private/named.conf を、/etc/bind/named.conf.local にインクルードさせます。
view "internal" {
[...]
// 追加
include "/var/lib/samba/private/named.conf";
};
/var/lib/ssamba/private/named.txt
続いて、同じく/var/lib/samba/private/named.txtを参照しながら、設定します。
# Additional informations for DNS setup using BIND
# If you are running a capable version of BIND and you wish to support
# secure GSS-TSIG updates, you must make the following configuration
# changes:
#
# Steps for BIND 9.8.x and 9.9.x -----------------------------------------
#
# 1. Insert following lines into the options {} section of your named.conf
# file:
tkey-gssapi-keytab "/var/lib/samba/private/dns.keytab";
#
# Common Steps for BIND 9.x.x --------------------------------------------
#
# 2. Set appropriate ownership and permissions on the dns.keytab file.
# Note that the most distributions have BIND configured to run under a
# non-root user account. For example, Fedora 9 runs BIND as the user
# "named" once the daemon relinquishes its rights. Therefore, the file
# dns.keytab must be readable by the user that BIND run as. If BIND
# is running as a non-root user, the "dns.keytab" file must have its
# permissions altered to allow the daemon to read it. Under Fedora 9,
# execute the following commands:
chgrp named /var/lib/samba/private/dns.keytab
chmod g+r /var/lib/samba/private/dns.keytab
# 3. Ensure the BIND zone file(s) that will be dynamically updated are in
# a directory where the BIND daemon can write. When BIND performs
# dynamic updates, it not only needs to update the zone file itself but
# it must also create a journal (.jnl) file to track the dynamic updates
# as they occur. Under Fedora 9, the /var/named directory can not be
# written to by the "named" user. However, the directory /var/named/dynamic
# directory does provide write access. Therefore the zone files were
# placed under the /var/named/dynamic directory. The file directives in
# both example zone statements at the beginning of this file were changed
# by prepending the directory "dynamic/".
# 4. If SELinux is enabled, ensure that all files have the appropriate
# SELinux file contexts. The dns.keytab file must be accessible by the
# BIND daemon and should have a SELinux type of named_conf_t. This can be
# set with the following command:
chcon -t named_conf_t /var/lib/samba/private/dns.keytab
この内、項目3は、ダイナミックDNSの設定、項目4はSENinux の設定方法なので、今回は割愛します。
/etc/bind/named.conf.opsions
keytab を、/etc/bind/named.conf.options に追加する。
options {
[...]
forwarders {
8.8.8.8; # プロバイダ等からの
X.Y.Z.A; # 指定されているDNS
};
// 追加
tkey-gssapi-keytab "/var/lib/samba/private/dns.keytab";
[...]
};
さらに、keytab のパーミッションを変更しておきます。
$ sudo chgrp bind /var/lib/samba/private/dns.keytab $ sudo chmod g+r /var/lib/samba/private/dns.keytab
AppArmorの設定
/etc/apparmor.d/local/usr.sbin.named に、以下を追加します。
# Site-specific additions and overrides for usr.sbin.named. # For more details, please see /etc/apparmor.d/local/README. # /usr/local/samba/lib/** rm, /var/lib/samba/** rm, /var/lib/samba/private/dns.keytab rmk, /var/lib/sanba/private/named.conf rmk, /var/lib/samba/private/dns/** rwk, /var/tmp/** rwmk, /usr/lib/x86_64-linux-gnu/samba/bind9/** rm, /usr/lib/x86_64-linux-gnu/samba/gensec/** rm, /usr/lib/x86_64-linux-gnu/ldb/modules/ldb/** rm, /usr/lib/x86_64-linux-gnu/samba/ldb/** rm, /dev/urandom rwc,
AppArmorの設定をリロード
$ sudo /etc/init.d/apparmor reload
BINDの再起動
$ sudo /etc/init.d/bind9 restart
エラーがないか、確認。
dns-nameserversの値を変更する
[...] dns-nameservers 192.168.1.100 [...]
その後、システムを再起動する。
Samba+BINDの設定チェック
hostコマンドによる名前解決の検証
hostコマンドで、LDAPサーバ、Kerberosサーバ、自IPのそれぞれが名前解決できるか確認。
$ host -t SRV _ldap._tcp.mydomain.local. _ldap._tcp.mydomain.local has SRV record 0 100 389 pdc.mydomain.com. $ host -t SRV _kerberos._udp.mydomain.local. _kerberos._udp.mydomain.local has SRV record 0 100 88 pdc.mydomain.com. $ host -t A pdc.mydomain.local. pdc.mydomain.local has address 192.168.1.100
Administrator としてログインできるか確認
$ smbclient //pdc.mydomain.local/netlogon -Uadministrator
Enter administrator's password:
Domain=[AD] OS=[Unix] Server=[Samba 4.1.6-Ubuntu]
smb: \> ls
. D 0 Sat Jan 17 15:38:46 2015
.. D 0 Sat Jan 17 15:38:55 2015
47348 blocks of size 131072. 25303 blocks available
smb: \> exit
$
smbclient でサーバと接続確認
$ sudo smbclient -L localhost -U%
Domain=[MYDOMAIN] OS=[Unix] Server=[Samba 4.1.6-Ubuntu]
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (Samba 4.1.6-Ubuntu)
shiro Disk
sysvol Disk
netlogon Disk
Domain=[MYDOMAIN] OS=[Unix] Server=[Samba 4.1.6-Ubuntu]
Server Comment
--------- -------
Workgroup Master
--------- -------
Kerberosの認証テスト
kerberosのチケットを発行
$ kinit administrator@MYDOMAIN.LOCAL Password for administrator@MYDOMAIN.LOCAL: Warning: Your password will expire in 40 days on 2015年04月11日 14時56分38秒
次に、kerberosが発行しているチケットの確認をする。
$ klist
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: administrator@MYDOMAIN.LOCAL
Valid starting Expires Service principal
2015-03-02T13:33:59 2015-03-02T23:33:59 krbtgt/MYDOMAIN.LOCAL@MYDOMAIN.LOCAL
renew until 2015-03-03T13:33:54
DNS自動更新のテスト
$ sudo samba_dnsupdate --verbose --all-names
まとめ
BIND9_DLZで設定した場合は、WindowsからGUI(RSAT)を使ってDNSの編集をすることができますが、FLATFILEはそれができません。
どちらにするか迷うところですが、FLATFILEは読んだままテキストファイルですので、*nix 使いの人はこちらのほうが親和性がありそう。好きなエディタで編集できますからね?
確認したところ、ドメインにコンピュータが参加する毎に、/var/lib/samba/private/dns/mydomain.local.zone ファイルに追加されていきます。また、手動でホストを追加してもエラーにはならないみたいです。