suzupy / noresore11

3 stars 0 forks source link

BINDセットアップ #6

Open ghost opened 6 years ago

ghost commented 6 years ago
yuuzi commented 6 years ago

・オープンリゾルバの対策 ・ゾーン転送の適切な設定 ・DNS amp対策 辺りも抑えて頂けると嬉しいです!

ghost commented 6 years ago

セットアップ手順

以下手順を参考に実施

インストール手順

https://go-journey.club/archives/395

confファイル

https://qiita.com/ToraLin/items/ae251b187d18de7684eb

セキュリティ設定について参考

Linuxサーバーセキュリティ徹底入門

権威DNSとキャッシュDNSの兼用パターン

ghost commented 6 years ago

DNSの基本設定

一旦、内部用にDNSを設定 慣れたら外部設定も入れる

設定内容

/etc/named.conf ```named.conf // // named.conf // // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS // server as a caching only nameserver (as a localhost DNS resolver only). // // See /usr/share/doc/bind*/sample/ for example named configuration files. // // See the BIND Administrator's Reference Manual (ARM) for details about the // configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html //アクセス制御リストを追加 acl locals { 192.168.1.0/24; }; //namedを操作できるホストのIPを指定する controls { inet 127.0.0.1 allow { localhost; }; }; options { //listen-on port 53 { 127.0.0.1; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; //BINDのバージョン情報を見せない version "unknown DNS Server"; /* - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion. - If you are building a RECURSIVE (caching) DNS server, you need to enable recursion. - If your recursive DNS server has a public IP address, you MUST enable access control to limit queries to your legitimate users. Failing to do so will cause your server to become part of large scale DNS amplification attacks. Implementing BCP38 within your network would greatly reduce such attack surface */ recursion yes; // キャッシュDNSサーバーとして動作します //再帰問合せを受け付ける範囲を指定 allow-recursion { localhost; locals; }; // リゾルバーとしての応答をlocalsからのみ許可します //allow-query { localhost; }; allow-query { any; }; // 何処からのクエリでも受け取ります allow-query-cache { locals; }; // キャッシュの内容をlocalsのみに返します dnssec-enable yes; dnssec-validation yes; /* Path to ISC DLV key */ bindkeys-file "/etc/named.iscdlv.key"; managed-keys-directory "/var/named/dynamic"; pid-file "/run/named/named.pid"; session-keyfile "/run/named/session.key"; }; //logging { // channel default_debug { // file "data/named.run"; // severity dynamic; // }; //}; logging { channel "default_debug" { file "data/named.run"; severity debug; print-time yes; print-severity yes; print-category yes; }; category queries { "default_debug"; }; category resolver { "default_debug"; }; category lame-servers { null; }; }; zone "." IN { type hint; file "named.ca"; }; //ゾーンファイル追加 zone "noresore.starbed.local" IN { type master; file "data/noresore.starbed.local"; //DNSが一台しかないのでゾーンの転送を許可しない allow-transfer { none; }; }; include "/etc/named.rfc1912.zones"; include "/etc/named.root.key"; ```
ghost commented 6 years ago

ゾーンファイル

Hardening10MP_参加者配布資料.pdfの6ページを参考に作成 実際のハードにングに近い命名規則でゾーンはnoresore.starbed.local にしています

ゾーンファイル

/var/named/data/noresore.starbed.local

$TTL 1D
@       IN SOA dm root (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        IN NS dm
        IN MX 10 mail
@       IN A 192.168.1.92
dm      IN A 192.168.1.92
mail    IN A 192.168.1.92
win     IN A 192.168.1.12
ec1     IN A 192.168.1.148
rp      IN A 192.168.1.127
ghost commented 6 years ago

コマンド系

named.confが正しいかどうか

named-checkconf /etc/named.conf

zoneファイルが正しいかどうか

named-checkzone zone名 /var/named/data/ゾーンファイル

bind確認

systemctl status named-chroot

自動起動化

再起動時に自動起動させる

systemctl enable named-chroot

設定できているか確認

[root@localhost data]# systemctl list-unit-files |grep named
named-chroot-setup.service                    static
named-chroot.service                          enabled
named-setup-rndc.service                      static
named.service                                 disabled
systemd-hostnamed.service                     static

1分おきにサービスを確認→ダウンしていたら起動させるスクリプト

シェルを作る

sudo vi /usr/local/sbin/check-named.sh

中身

#! /bin/bash

#監視するプロセス名を定義する
PROCESS_NAME=named-chroot

#監視するプロセスが何個起動しているかカウントする
count=`ps -ef | grep $PROCESS_NAME | grep -v grep | wc -l`

#監視するプロセスが0個場合に、処理を分岐する
if [ $count = 0 ]; then

#0個場合は、サービスが停止しているので起動する
  echo "$PROCESS_NAME Down"
  echo "$PROCESS_NAME Start"

# Cent OS 6.xの場合は、以下を使用する
#  /etc/init.d/httpd restart
# Cent OS 7.xの場合は、以下を使用する
  systemctl restart named-chroot

else
  echo "$PROCESS_NAME OK"
fi

パーミッション変更

chmod 700 /usr/local/sbin/check-named.sh

crontabで1分ごとに確認

sudo vi /etc/crontab

crontabの中身

  */1  *  *  *  * root    /bin/bash /usr/local/sbin/check-named.sh
ghost commented 6 years ago

自分のネットワーク内の名前解決はできるが、キャッシュサーバとして動いてくれない。

ghost commented 6 years ago

自分の仮想環境ではキャッシュサーバとして動くので、AWS環境特有の事象っぽい。

参考 https://qiita.com/mechamogera/items/574de60310fb19e088ca