この記事を作った動機

 ある時、ChatGPT を使っていて、うまく設定が読み込めないという時があったときにそれについて調べてみたら、DNS 周りのキャッシュがおかしい説というのがあり、named のキャッシュを消そうとしてやり方がわからなかったので、自分用に記録するだけ。

設定する

 少なくとも私の環境では、最初から rndc コマンドは使えるようになっておらず、設定が必要だった。rndc-confgen を使うことで、コンフィグは生成できるので、出てきたものをそれぞれ、named.confrndc.conf に貼り付ければとりあえずは動いた。

まだ設定がないときの rndc コマンドの挙動

sudo rndc status
# rndc: no server specified and no default

rndc status -s localhost
# rndc: no server specified and no default

rndc-confgen で設定を生成する

# sudo rndc-confgen 
[sudo] share のパスワード:
# Start of rndc.conf
key "rndc-key" {
	algorithm hmac-sha256;
	secret "secretString";
};

options {
	default-key "rndc-key";
	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 "rndc-key" {
# 	algorithm hmac-sha256;
# 	secret "secretString";
# };
# 
# controls {
# 	inet 127.0.0.1 port 953
# 		allow { 127.0.0.1; } keys { "rndc-key"; };
# };
# End of named.conf

設定を貼り付ける

/etc/rndc.conf (なければ作成する)

key "rndc-key" {
	algorithm hmac-sha256;
	secret "secretString";
};

options {
	default-key "rndc-key";
	default-server 127.0.0.1;
	default-port 953;
};

/etc/named.conf (追記する)

key "rndc-key" {
	algorithm hmac-sha256;
	secret "secretString";
};

controls {
	inet 127.0.0.1 port 953
		allow { 127.0.0.1; } keys { "rndc-key"; };
};

systemd で named を再起動する

sudo systemctl restart named

キャッシュを削除する

sudo rndc flush

参考にしたサイトとか