Spamassassin: Bypass /etc/resolv.conf DNS for querying DNSBL?

Spamassassin (Mail::SpamAssassin::DnsResolver) uses Net::DNS::Resolver perl module.
It should allow you to change nameservers spamassassin uses via RES_NAMESERVERS environment variable.


I had set up BIND Named on my laptop, following an old version of Spamassassin's documentation to "Disable forwarding for DNSBL queries"; it requires that I point /etc/resolv.conf to 127.0.0.1.

But I could only get this to work by putting

static domain_name_servers=127.0.0.1

at the end of /etc/dhcpcd.conf. Then I had to copy the value which is usually in /etc/resolv.conf into /etc/named.conf (forwarders { 192.168.1.1; }). This worked great until I would take my laptop somewhere else, when after connecting to a new DHCP server I would be surprised to find DNS not working, because I had pointed Named to an old local address.

Much better in my opinion to avoid this problem by having only Spamassassin using the local Named; so I restored the original dhcpcd.conf and pointed Spamassassin to 127.0.0.1. You can do this in one of two ways:

Following the answer of AnFi, you can change the environment e.g. in the service file /etc/systemd/system/spamassassin.service:

[Service]
Environment="RES_NAMESERVERS=127.0.0.1"
...

But according to the above document you can also configure this in Spamassassin's configuration file local.cf. This is perhaps more elegant:

dns_server 127.0.0.1