カスタム検索
tomo.gif (1144 ツバツイツト)line.gif (927 ツバツイツト)line.gif (927 ツバツイツト)To previous pageTo home pageMailing to me

rndcの小技

Modified: 1 December 2002

rndc(remote name server daemon control)とは、BINDを動作させたまま、動作状態の確認や設定ファイルのリロードを行うことができます。

他のPCから遠隔制御も可能です。遠隔制御では、セキュリティのため暗号化通信路を作成し、安全に通信することができるようになっています。


他のPCからrndcを使えるようにする方法1 December 2002
rndcを暗号化通信路を用いて使う方法
1 December 2002


 他のPCからrndcを使えるようにする方法

"named.conf"の"controls"を変更する

"rndc"の制御に関する設定は、"named.conf"の"controls"で行います。

デフォルトでは、以下のように、BINDが動作しているPCから(ローカルポート)しか使うことができません。

controls {
      inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};

外部のPCから使う場合は、以下のように、IPアドレスを記述します。

controls {
      inet 192.168.0.85
      allow { 192.168.0.85; 192.168.0.87; }
      keys { rndckey; };
};

inetのところは、BINDが動作しているPCのIPアドレスで、外部からの制御を受け入れるアドレスとなります。

allowのところは、rndcを使うPCのIPアドレスです。

上記の設定では、192.168.0.85が、BINDが動作しているPCのIPアドレスで、192.168.0.85と192.168.0.87のrndcで、192.168.0.85のBINDの動作を制御できます。


動作確認

デフォルト設定での動作

デフォルトの設定では、BINDの動作しているPC(192.168.0.85)で実行すると、以下のようになります。

サーバーを指定しない場合、"localhost"がデフォルトなので、うまく表示できます。

# /usr/sbin/rndc status
number of zones: 6
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
server is up and running
#

"localhost"を明記した場合も、うまく表示できます。

# /usr/sbin/rndc -s 127.0.0.1 status
number of zones: 6
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
server is up and running
#

BINDが動作しているPC(192.168.0.85)でも、IPアドレスを指定すると拒否されます。

# /usr/sbin/rndc -s 192.168.0.85 status
rndc: connect failed: connection refused
#

他のPC(192.168.0.86)からIPアドレスを指定しても拒否されます。

# /usr/sbin/rndc -s 192.168.0.87 status
rndc: connect failed: connection refused
#


設定後の動作確認

以下の設定をしました。

controls {
      inet 192.168.0.85
      allow { 192.168.0.85; 192.168.0.87; }
      keys { rndckey; };
};

BINDが動作しているPC(192.168.0.85)からIPアドレスを指定すればうまく動作します。

# /usr/sbin/rndc -s 192.168.0.85 status
number of zones: 6
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
server is up and running
#

他のPC(192.168.0.87)からBINDが動作しているPC(192.168.0.85)のIPアドレスを指定すればうまく動作します。

# /usr/sbin/rndc -s 192.168.0.87 status
number of zones: 6
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
server is up and running
#

許可リスト(allow)に記述されていない、他のPC(192.168.0.86)からBINDが動作しているPC(192.168.0.85)のIPアドレスを指定しても拒否されます。

# /usr/sbin/rndc -s 192.168.0.86 status
rndc: connect failed: connection refused
#

では、ローカルホストはどうでしょう。IPアドレスを使うようにしたので、拒否されるようになりました。

# /usr/sbin/rndc -s 127.0.0.1 status
rndc: connect failed: connection refused
#

サーバーを指定しない場合も、デフォルトがローカルホストなので、拒否されるようになりました。

# /usr/sbin/rndc status
rndc: connect failed: connection refused
#

 rndcを暗号化通信路を用いて使う方法

共通暗号鍵(HMAC-MD5)を作成する

以下のコマンドで、共通暗号鍵(HMAC-MD5)を、"key.txt"のファイル名で作成します。

"-b 512" は、鍵の長さです。"-k tomo" は、任意の名前です。

# /usr/sbin/rndc-confgen -b 512 -k tomo > key.txt
#

作成された"key.txt"は以下のように作られます。

# Start of rndc.conf
key "tomo" {
        algorithm hmac-md5;
        secret "UURHym1odzh+oZzHUzgk/W/RYiKO2mra0nmf0/BX1kwLmY5KQDeVGoOSafWr5mMZuGCWzH6iQnza7bD5adNMYw==";
};

options {
        default-key "tomo";
        default-server 127.0.0.1;
        default-port 953;
};
# End of rndc.conf

# Use with the following in named.conf, adjusting the allow list as needed:
# key "tomo" {
#       algorithm hmac-md5;
#       secret "UURHym1odzh+oZzHUzgk/W/RYiKO2mra0nmf0/BX1kwLmY5KQDeVGoOSafWr5mMZuGCWzH6iQnza7bD5adNMYw==";
# };
#
# controls {
#       inet 127.0.0.1 port 953
#               allow { 127.0.0.1; } keys { "tomo"; };
# };
# End of named.conf


"rndc.conf"を作成する

作成された"key.txt"の前半の"Start of rndc.conf"から"End of rndc.conf"までを、rndcを使うPCに、"/etc/rndc.conf"で保存します。

# Start of rndc.conf
key "tomo" {
        algorithm hmac-md5;
        secret "UURHym1odzh+oZzHUzgk/W/RYiKO2mra0nmf0/BX1kwLmY5KQDeVGoOSafWr5mMZuGCWzH6iQnza7bD5adNMYw==";
};

options {
        default-key "tomo";
        default-server 127.0.0.1;
        default-port 953;
};
# End of rndc.conf

他のPC(192.168.0.86)から使う場合は、rndcを使うPC(192.168.0.87)内の"rndc.conf"のIPアドレスを以下のように変更して、rndcコマンドを使うPCに保存します。

私は、BINDを動かしているPC(192.168.0.85と、別のPC(192.168.0.87の2つのPCからBINDを制御したいので、それぞれのPCに、以下の同じファイルを、"/etc/rndc.conf"、保存しました。

# Start of rndc.conf
key "tomo" {
        algorithm hmac-md5;
        secret "UURHym1odzh+oZzHUzgk/W/RYiKO2mra0nmf0/BX1kwLmY5KQDeVGoOSafWr5mMZuGCWzH6iQnza7bD5adNMYw==";
};

options {
        default-key "tomo";
        default-server 192.168.0.85;
        default-port 953;
};
# End of rndc.conf

"/etc/rndc.conf"は、デフォルトの設定ファイルが存在していますが、サンプルですので、上書きして入れ替えればOKです。


"named.conf"に設定を追加する

BINDが動作しているPCには、後半の"Use with the following ...."から"End of named.conf"までのコメントをカットして、"named.conf"に追加します。

# Use with the following in named.conf, adjusting the allow list as needed:
key "tomo" {
      algorithm hmac-md5;
      secret "UURHym1odzh+oZzHUzgk/W/RYiKO2mra0nmf0/BX1kwLmY5KQDeVGoOSafWr5mMZuGCWzH6iQnza7bD5adNMYw==";
};
controls {
      inet 127.0.0.1 port 953
              allow { 127.0.0.1; } keys { "tomo"; };
};
# End of named.conf

他のPCからのアクセスを受け入れる場合は、以下のように、"controls"を変更します。

# Use with the following in named.conf, adjusting the allow list as needed:
key "tomo" {
      algorithm hmac-md5;
      secret "UURHym1odzh+oZzHUzgk/W/RYiKO2mra0nmf0/BX1kwLmY5KQDeVGoOSafWr5mMZuGCWzH6iQnza7bD5adNMYw==";
};
controls {
      inet 192.168.0.85 port 953
              allow { 192.168.0.85; 192.168.0.87; } keys { "tomo"; };
};
# End of named.conf

上記設定で、BINDを動かしているPC(192.168.0.85)と、外部のPC(192.168.0.87)からrndcを暗号化された状態で使うことができます。


動作確認する

BINDが動作しているPC(192.168.0.85で動作確認します。

# /usr/sbin/rndc -s 192.168.0.85 status
number of zones: 6
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
server is up and running
#

別のPC(192.168.0.87で動作確認します。

# /usr/sbin/rndc -s 192.168.0.85 status
number of zones: 6
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
server is up and running
#

上記のようにステータスが表示されればOKです。


To previous pageTo home pageMailing to meJump to Top of pageline.gif (927 ツバツイツト)tomo.gif (1144 ツバツイツト)
カスタム検索


Tweet