Automatic DNS management via RFC2136 (TSIG) and Bind 9 not worked: invalid command from 192.168.X.X#XXXXX: out of range

Issue Description

I can’t make friends with Stalwart and Bind9 in any way, can anyone tell me what the mistake might be?
A brief description of the actions is provided below.
I use TCP port 953 for synchronization.

Reproduction Steps

root@ns0:/var/lib/bind# named -v
BIND 9.20.24-1ubuntu0.3-Ubuntu (Stable Release) id:
root@ns0:/var/lib/bind#

/etc/bind/named.conf

key “stalwart” {
algorithm hmac-sha256;
secret “ckzcjcAHqTZAWg2GsrIZnzdJAMWdAPauLxW5lY3SjSc=”;
};

controls {
inet 192.168.0.236 port 953
allow {
192.168.0.229;
} keys {
“stalwart”;
};
};

root@ns0:/var/lib/bind# named-checkconf
root@ns0:/var/lib/bind# systemctl restart named

…

root@ns0:/var/lib/bind# date -u

eq (+/- 1 second)

root@stalwart:/var/lib/bind# date -u

Go to: http://stalwart:8080/admin/Management/x:Domain
Switch DNS from Automatic to Manual, and back to Automatic.

Relevant Log Output

/var/log/syslog | grep named

2026-10-12T11:15:13.301445+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60366: out of range
2026-10-12T11:15:13.302183+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60380: out of range
2026-10-12T11:15:13.303343+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60388: out of range
2026-10-12T11:15:13.304430+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60404: out of range
2026-10-12T11:15:13.305517+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60420: out of range
2026-10-12T11:15:13.306526+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60430: out of range
2026-10-12T11:15:13.307481+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60434: out of range
2026-10-12T11:15:13.308412+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60440: out of range
2026-10-12T11:15:13.309327+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60446: out of range
2026-10-12T11:15:13.310135+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60462: out of range
2026-10-12T11:15:13.311021+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60464: out of range
2026-10-12T11:15:13.311843+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60476: out of range
2026-10-12T11:15:13.312765+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60492: out of range
2026-10-12T11:15:13.313649+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60506: out of range
2026-10-12T11:15:13.314450+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60518: out of range
2026-10-12T11:15:13.315432+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60520: out of range
2026-10-12T11:15:13.316367+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60532: out of range
2026-10-12T11:15:13.317140+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60548: out of range
2026-10-12T11:15:13.317976+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60556: out of range
2026-10-12T11:15:13.318564+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60564: out of range
2026-10-12T11:15:13.319444+00:00 ns0 named[5516]: invalid command from 192.168.0.229#60570: out of range

Stalwart Version

v0.16.x

Installation Method

Binary (Linux)

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

The “invalid command … out of range” error is a BIND/rndc protocol error, not a Stalwart issue: it happens because the TSIG channel you set up is the rndc remote-control channel (controls { inet … port 953 … }), not a DNS update channel. Stalwart’s RFC2136/TSIG provider doesn’t speak the rndc protocol at all — it sends standard DNS UPDATE messages (RFC 2136) over the normal DNS port, authenticated with the TSIG key. That’s why BIND, which is expecting rndc control-protocol bytes on port 953, logs “invalid command… out of range” when it receives a raw DNS UPDATE packet instead.

To fix it:

  1. Remove/ignore the controls { … } block for this purpose — that’s only for rndc administrative commands, unrelated to dynamic DNS updates.
  2. Authorize the TSIG key to update the zone directly in the zone definition, e.g.:
    zone "example.com" {
        type primary;
        file "/etc/bind/db.example.com";
        allow-update { key "stalwart"; };
    };
    
  3. In Stalwart’s DNS provider settings (Settings › Network › DNS › DNS Providers, Tsig type), point host/port at BIND’s normal DNS listener (default port 53, not 953), with the matching keyName, key, and tsigAlgorithm (make sure the algorithm matches what you defined, e.g. hmac-sha256).

See the DNS Providers and DnsServer reference pages for the exact field list for the Tsig variant.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

zone “example.com” {
type master;
file “/var/lib/bind/example.com.dns”;
allow-transfer { office1; };
allow-update { key stalwart; };
};

Port 953 is BIND’s rndc control channel, not where DNS updates go. Stalwart sends standard RFC 2136 UPDATE messages, and the control channel can’t parse those, which is the “invalid command … out of range” in your log. Point the DNS server in Stalwart at port 53 on ns0 and remove the controls block, it isn’t needed for this. The allow-update { key stalwart; }; on the zone is the part that matters, and it’s already correct.

Your key is hmac-sha256 while Stalwart defaults to hmac-sha512, so also set the TSIG algorithm to hmac-sha256 and the key name to stalwart (fields are listed at DnsServer | Stalwart). named also needs write access to /var/lib/bind for the zone journal.

The secret in your post is the real one, so I’d generate a new key with tsig-keygen -a hmac-sha256 stalwart and update both sides.