Build a Syslog Collector with rsyslog on Debian 13: TLS, Per-Host Log Files and Rotation
Every lab I build ends up needing somewhere for the routers, firewalls and switches to send their logs. A syslog collector is the simplest real piece of infrastructure you can build, and rsyslog does it in about twenty lines of configuration.
I built one on my Debian 13 test VM. To keep the VM’s own logging untouched, the collector and the senders run as separate rsyslog instances inside network namespaces, so everything below is tested against a real TCP and TLS connection across a veth pair.
Packages and versions
sudo apt install rsyslog rsyslog-gnutls openssl logrotate
rsyslog 8.2504.0-1+deb13u2
rsyslog-gnutls 8.2504.0-1+deb13u2
logrotate 3.22.0-1
openssl 3.5.7-1~deb13u3
rsyslog-gnutls is the separate package that adds TLS. Without it, a config that asks for the gtls driver fails.
Certificates
For mutual TLS you need a CA, a certificate for the collector and one per sender. A throwaway lab CA:
openssl req -x509 -newkey rsa:2048 -nodes -keyout ca.key -out ca.pem -days 30 -subj "/CN=Lab Syslog CA"
mk() {
openssl req -newkey rsa:2048 -nodes -keyout $1.key -out $1.csr -subj "/CN=$1"
printf "subjectAltName=DNS:$1" > $1.ext
openssl x509 -req -in $1.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out $1.pem -days 30 -extfile $1.ext
}
mk collector; mk fw01; mk sw02
Each certificate carries its name as a SAN, which matters in a moment. For anything beyond a lab, use a CA you actually protect and set realistic lifetimes.
The collector
global(
DefaultNetstreamDriver="gtls"
DefaultNetstreamDriverCAFile="/etc/rsyslog.d/tls/ca.pem"
DefaultNetstreamDriverCertFile="/etc/rsyslog.d/tls/collector.pem"
DefaultNetstreamDriverKeyFile="/etc/rsyslog.d/tls/collector.key"
)
module(load="imtcp")
input(type="imtcp" port="514" streamDriver.mode="0")
input(type="imtcp" port="6514" streamDriver.mode="1"
streamDriver.authMode="x509/name"
permittedPeer=["fw01","sw02"])
template(name="PerHost" type="string"
string="/srv/syslog/%HOSTNAME%/%programname%.log")
template(name="Fmt" type="string"
string="%timegenerated:::date-rfc3339% %HOSTNAME% %programname%: %msg%\n")
*.* action(type="omfile" dynaFile="PerHost" template="Fmt")
What each part does:
- Two
inputlines on oneimtcpmodule: port 514 in plain TCP (mode 0) and 6514 with TLS (mode 1). The mode is set per input, so you can run both side by side while you migrate devices that cannot do TLS. authMode="x509/name"pluspermittedPeermeans a client must present a certificate signed by the CA and its name must be on the list. A valid certificate is not enough.dynaFilewith thePerHosttemplate creates/srv/syslog/<hostname>/<program>.logon demand. No directories to pre-create.
Two gotchas from the writing of this config. permittedPeer is the working parameter name on 8.2504, and my first attempt with streamDriver.permittedPeers was rejected by rsyslogd -N1 (“parameter not known”). Always run the config check before restarting:
sudo rsyslogd -N1 -f /etc/rsyslog.d/10-collector.conf
And the plain port 514 has no authentication at all, so anyone who can reach it can write into your logs. Firewall it to the devices that need it.
A sender
A TLS sender is a forwarding action:
global(
localHostname="fw01"
DefaultNetstreamDriver="gtls"
DefaultNetstreamDriverCAFile="/etc/rsyslog.d/tls/ca.pem"
DefaultNetstreamDriverCertFile="/etc/rsyslog.d/tls/fw01.pem"
DefaultNetstreamDriverKeyFile="/etc/rsyslog.d/tls/fw01.key"
workDirectory="/var/spool/rsyslog"
)
*.* action(type="omfwd" target="10.60.0.1" port="6514" protocol="tcp"
StreamDriver="gtls" StreamDriverMode="1"
StreamDriverAuthMode="x509/name" StreamDriverPermittedPeers="collector"
action.resumeRetryCount="-1" action.resumeInterval="2"
queue.type="LinkedList" queue.filename="q_fw01" queue.saveOnShutdown="on")
The sender checks the collector’s name too (StreamDriverPermittedPeers="collector"), so both directions are authenticated. A plain TCP sender is the same action without the StreamDriver* lines and with port 514.
In my lab the senders were fed with logger -u <socket>, and the host name in the log comes from localHostname. I sent three messages:
logger -u /tmp/rs/fw01.sock -t sshd "Accepted publickey for admin from 10.0.0.9"
logger -u /tmp/rs/fw01.sock -t kernel "eth1: link down"
logger -u /tmp/rs/sw02.sock -t bgpd "neighbor 10.0.0.1 Down"
and the collector’s tree looked like this:
logs/fw01/kernel.log
logs/fw01/sshd.log
logs/sw02/bgpd.log
2026-11-02T20:45:45.790956+00:00 fw01 sshd: Accepted publickey for admin from 10.0.0.9
2026-11-02T20:45:45.791307+00:00 fw01 kernel: eth1: link down
One directory per host, one file per program. That layout makes grep -r "Down" /srv/syslog/sw02/ an easy question.
What the wire looks like
I captured both ports while sending a marker string to each:
514 canary visible: 1
6514 canary visible: 0
On 514 the capture shows the whole message in clear text, <13>Nov 2 20:46:28 sw02 bgpd: PLAINTEXT-CANARY-514. On 6514 the marker string does not appear anywhere in the capture. If your logs contain usernames, source addresses and failed logins, that difference is the argument for TLS.
Rejecting clients
I started two bad senders pointed at port 6514: one with a certificate signed by my CA but named intruder, and one with a self-signed certificate named rogue. Neither created a file in /srv/syslog. The collector said why on its stderr:
rsyslogd: error: peer name not authorized - not permitted to talk to it. Names: DNSname: intruder; CN: intruder;
rsyslogd: invalid cert info: peer provided 1 certificate(s). ... DN: CN=rogue; Issuer DN: CN=rogue;
rsyslogd: not permitted to talk to peer '10.60.0.2', certificate invalid: signer not found
Those two messages are the ones to search for when a legitimate device cannot connect: peer name not authorized means the name is not in permittedPeer, and signer not found means the CA is wrong. openssl s_client is a quick check from the sender’s side:
$ openssl s_client -connect 10.60.0.1:6514 -CAfile ca.pem
subject=CN=collector
issuer=CN=Lab Syslog CA
Verification: OK
Protocol: TLSv1.3
Cipher is TLS_AES_256_GCM_SHA384
Surviving a collector outage
With the collector stopped, I sent three messages from a plain TCP sender, restarted the collector, and waited:
2026-11-02T20:48:09.722901+00:00 sw02 bgpd: held #1
2026-11-02T20:48:09.722901+00:00 sw02 bgpd: held #2
2026-11-02T20:48:09.722901+00:00 sw02 bgpd: held #3
All three arrived after the collector came back. This depends on action.resumeRetryCount="-1", which means retry forever. Without a retry setting, an action that fails gives up and the messages are lost, so this is the line I would never leave out on a sender. Note that this is the sender holding messages in its queue. A collector with no queue behind it loses anything sent while it is down.
Rotation
Left alone, per-host files grow forever. A logrotate stanza:
/srv/syslog/*/*.log {
daily
rotate 14
missingok
notifempty
compress
delaycompress
dateext
sharedscripts
postrotate
systemctl kill -s HUP rsyslog.service
endscript
}
In the lab I used kill -HUP on the collector’s pid file in the postrotate. I forced a rotation with logrotate -f and the result was as expected:
logs/fw01/kernel.log-20261102
logs/fw01/sshd.log
logs/fw01/sshd.log-20261102
logs/sw02/bgpd.log-20261102
and the second forced run compressed the older file to sshd.log-20261102.gz. delaycompress leaves the newest rotated file uncompressed so rsyslog can finish writing to it after the HUP. Also note logrotate refused to rotate twice in one day with dateext (“destination … already exists, skipping rotation”), which is the guard doing its job in a test.
The HUP matters: rsyslog keeps files open, and without it, it keeps writing to the rotated-away file.
Production notes I did not test
- The lab used files under
/tmpand instances in namespaces. On a real host, the config goes in/etc/rsyslog.d/, keys are mode 600 and readable only by the rsyslog user, and logs go on a filesystem with space to spare. - Open the ports with your firewall, 6514 to the senders and 514 only if you must.
- A flood from one device can fill the disk. Alert on free space and on the size of the biggest directory.
- I attempted a burst test of several thousand messages, but my sender socket test did not produce a usable result, so I have no throughput figure for you.
Verdict
A collector with authenticated TLS, a directory per host and rotation is about forty lines of configuration across three files, and each failure mode has a specific error message. The setting people most often omit is the retry on the sender, and the one that bites later is rotation.