Samba4+BIND9_DLZ で設定した時のまとめ。
まだ、ADにクライアントを参加させての検証をしていないので、エラーなく動作するかどうかは不明。参考の覚書として・・

概ね、SambaWiki の DNS Backend 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固有の番号がつきます。</pre>
ACLパッケージをインストール。
<pre class="toolbar:2 nums:false lang:sh decode:true  ">$ 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;
    };

    //zone "mydomain.local" {
    //  type master;
    //  file "/etc/bind/db.mydomain.local";
    //  #   allow-update { none; };
    //};

    //zone "168.192.in-addr.arpa" {
    //  type master;
    //  file "/etc/bind/db.168.192.in-addr.arpa";
    //  #   allow-update { none; };
    //};
};

ここでコメントアウトしてあるのは、当初自分自身で設定した、ローカルのゾーン設定なんですが、Samba4でBIND_DLZを利用すると、ローカルのゾーン設定はそちらがするみたいで、この部分を活かしたままだとゾーンが重複してBIND起動時にエラーになります。

Mar  2 11:01:22 pdc named[1620]: Loading 'AD DNS Zone' using driver dlopen
Mar  2 11:01:22 pdc named[1620]: samba_dlz: started for DN DC=mydomain,DC=local
Mar  2 11:01:22 pdc named[1620]: samba_dlz: starting configure
Mar  2 11:01:22 pdc named[1620]: samba_dlz: Failed to configure zone 'mydomain.local'
Mar  2 11:01:22 pdc named[1620]: loading configuration: already exists
Mar  2 11:01:22 pdc named[1620]: exiting (due to fatal error)
ゾーン設定の確認

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の設定画面が出てきて、設定をするように促されますので、概ね以下のとおりに設定。

  • レルム:
  • あなたのレルムのケルベロスサーバー(kdc):
  • あなたのレルムのケルベロス管理サーバー(admin_server):
  • MYDOMAIN.LOCAL
  • pdc.mydomain.local
  • pdc.mydomain.local
samba-toolでSambaの使用準備をする

まず、デフォルトで作成された設定ファイルを削除か、リネームします。

$ sudo rm /etc/samba/smb.conf

samba-tool で、sambaの基本的な設定をします。

ここでは、DNS backend = BIND9_DLZとして進めていきます。また、この場合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_DLZ
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

BINDをSamba4 AD のバックエンドとして設定する

/var/lib/samba/private/named.confの編集

BINDのバージョンによって、コメントアウトを外します。
Ubuntu14.04の場合、For BIND 9.9.0 を選択します。

# This DNS configuration is for BIND 9.8.0 or later with dlz_dlopen support.
#
# This file should be included in your main BIND configuration file
#
# For example with
# include "/var/lib/samba/private/named.conf";

#
# This configures dynamically loadable zones (DLZ) from AD schema
# Uncomment only single database line, depending on your BIND version
#
dlz "AD DNS Zone" {
    # For BIND 9.8.0
    #database "dlopen /usr/lib/x86_64-linux-gnu/samba/bind9/dlz_bind9.so";

    # For BIND 9.9.0
    database "dlopen /usr/lib/x86_64-linux-gnu/samba/bind9/dlz_bind9_9.so";
};
/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 に、以下を追加します。
※2015年3月14日追記
SambaWikiとは少し異なりますが、これでようやくBindも動くようになりました。

# 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

syslogをチェックして、エラーが無いかどうか確認し、エラーがあった場合は対処します。ここまでの設定を順序立ててしていれば、出ないはず・・

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

ここで、先の/etc/hosts の127.0.1.1のエントリを消しておかないと、自動更新に失敗します。

関連項目

更新履歴

2015年3月14日 /etc/apparmor.d/local/usr.sbin.named の内容を変更しました。
2015年3月16日 一連の流れでわかるように、先の[samba] Ubuntu14.04でSamba4のまとめの内容を加えました。


 

 
カテゴリー: bind9Samba4

zaturendo

中小企業社内SE。

3件のコメント

匿名 · 2020年7月2日 5:30 PM

Köszönöm! Nagyszerű leírás!

ありがとう!素晴らしい説明。

gergely · 2020年7月2日 6:53 PM

HU: Köszönöm! Nagyszerű magyarázat!

JP: ありがとう!素晴らしい説明。

    zaturendo · 2020年7月25日 6:49 AM

    コメント頂きありがとうございます。
    今後もよろしくお願いします!

匿名 へ返信する コメントをキャンセル

アバタープレースホルダー

メールアドレスが公開されることはありません。 が付いている欄は必須項目です