ClamAV: test the clamd connection (PING and VERSION)
How to check that the clamd daemon answers on its UNIX socket or TCP port, and how to align client applications with it.
Applications that scan files with ClamAV send them to the clamd daemon. When the client logs Connection to clamd failed followed by Connection to clamd re-established, the daemon is not answering on the endpoint the client uses. The checks below confirm which endpoint clamd exposes and whether it answers.
1. Check the daemon
systemctl list-units '*clam*'
systemctl status clamd.service
journalctl -u clamd.service -b --no-pager
In the journal, look for restarts, out-of-memory kills or segmentation faults.
2. Check the endpoint in clamd.conf
grep -E '^(LocalSocket|TCPSocket|TCPAddr)' /etc/clamav/clamd.conf
| Setting | Example | Use |
|---|---|---|
LocalSocket |
/run/clamav/clamd.ctl |
UNIX socket, local clients only |
TCPSocket |
3310 |
TCP port |
TCPAddr |
127.0.0.1 |
Address the TCP port listens on |
For a UNIX socket, the user of the client application must be able to reach it:
ls -l /run/clamav/clamd.ctl
If needed, set LocalSocketGroup (for example the web server group) and LocalSocketMode in clamd.conf. The source used mode 666, which lets every local user connect; restrict it to the web server group when possible.
Restart after any change:
sudo systemctl restart clamd.service
3. Send PING and VERSION
Over TCP:
echo PING | nc -w 2 127.0.0.1 3310
echo VERSION | nc -w 2 127.0.0.1 3310
Over the UNIX socket, with ncat (package nmap) or socat:
printf "PING\n" | ncat -U /run/clamav/clamd.ctl
printf "VERSION\n" | ncat -U /run/clamav/clamd.ctl
printf "PING\n" | socat - UNIX-CONNECT:/run/clamav/clamd.ctl
printf "VERSION\n" | socat - UNIX-CONNECT:/run/clamav/clamd.ctl
The GNU nc does not support -U. OpenBSD netcat does, and is an alternative to ncat or socat.
Expected results: PING returns PONG, and VERSION returns the clamd version string.
4. Scan one file from the command line
clamdscan --fdpass /path/to/file
clamscan /path/to/file
clamscanworks butclamdscanfails: the problem is the endpoint or its permissions.- Both fail: the ClamAV installation or its signature databases are the problem.
Notes
- The client application must use the same endpoint as
clamd: the same UNIX socket path, or the same IP address and port.