install and configure rspamd

How to Install Rspamd in Ubuntu

Rspamd is a powerful spam filtering system for mail servers. It is written in C language and is quite fast in performance. It is highly customizable and allows you to use different strategies to combat spam. You can evaluate every message using regular expressions, statistical analysis and black lists. In this article, we will look at how to install Rspamd in Ubuntu.


How to Install Rspamd in Ubuntu

Here are the steps to install Rspamd in Ubuntu.


1. Install Redis

Rspamd requires a data storage & caching system. We will be using Redis for this purpose. Open terminal and run the following command to install Redis.

$ sudo apt install redis-server


2. Install Unbound

We will also need Unbound, a secure DNS resolver. It reduces the number of external DNS requests and improves performance. You can skip this step if you want.

Run the following commands to install Unbound.

$ sudo apt update
$ sudo apt install unbound

The default Unbound settings are enough for Rspamd configuration. Run the following commands to set it as default DNS resolver.

$ sudo echo "nameserver 127.0.0.1" >> /etc/resolvconf/resolv.conf.d/head
$ sudo resolvconf -u


3. Install Rspamd

Now we will install Rspamd. First, we will install required packages.

$ sudo apt install software-properties-common lsb-release
$ sudo apt install lsb-release wget

Next, we will add repository GPG key to sources list on our system.

$ wget -O- https://rspamd.com/apt-stable/gpg.key | sudo apt-key add -

Enable Rspamd repository with the following command.

$ echo "deb http://rspamd.com/apt-stable/ $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/rspamd.list

Once we have enabled the repository, we install rpamd with the following command.

$ sudo apt update
$ sudo apt install rspamd


4. Configure Rspamd

We will create a config file for Rspamd at /etc/rspamd/local.d/local.d/ which will overwrite the default configuration.

Run the following command to create the config file for normal worker.

$ sudo vi /etc/rspamd/local.d/worker-normal.inc

Add the following line to ensure that Rspamd listens to only local port 11333. By default, it also listens to port 11333 on all interfaces.

bind_socket = "127.0.0.1:11333";

Save and close the file. Next, create the config file for worker proxy that listens to port 11332.

$ sudo /etc/rspamd/local.d/worker-proxy.inc

Add the following lines to enable milter protocol and allow other tools like Postfix to communicate with it.

bind_socket = "127.0.0.1:11332";
milter = yes;
timeout = 120s;
upstream "local" {
  default = yes;
  self_scan = yes;
}

Save and close the file. Next, we setup a password for controller worker with the following command. Replace password_here with a password of your choice.

$ rspamadm pw --encrypt -p password_here

You will see an output like the following

$4$ghz7u8nxgggsfay3qta7ousbnmi1skew$tdat4nsm7nd3ctmiigx8kjyo837hcjodn1bob5jaxt7xpkieoctb

Copy it.

Create a new file with the following command, for controller worker.

$ sudo /etc/rspamd/local.d/worker-controller.inc

Add the following line to it.

password = "$4$ghz7u8nxgggsfay3qta7ousbnmi1skew$tdat4nsm7nd3ctmiigx8kjyo837hcjodn1bob5jaxt7xpkieoctb";

Save and close the file. Next, we will configure Rspamd to work with Redis. Open classifier-bayes.conf file.

$ sudo vi /etc/rspamd/local.d/classifier-bayes.conf

Add the following line.

servers = "127.0.0.1";
backend = "redis";

Save and close the file. Next, open milter_headers.conf file. Add the following line.

use = ["x-spamd-bar", "x-spam-level", "authentication-results"];

Save and close the file. Run the following command to restart Rspamd server.

$ sudo systemctl restart rspamd


5. Configure Web Interface

Finally, we will configure the web interface for Rspamd that allows you to see detailed stats about its performance. For this purpose, you need a web server. We will use NGINX for this purpose. Run the following command to install NGINX.

$ sudo apt install nginx

Open its configuration file in a text editor, or create a new one as shown below

/etc/nginx/sites-enabled/example.conf

Add the following lines to it.

location /rspamd {
    proxy_pass http://127.0.0.1:11334/;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Save and close the file. Restart NGINX to apply changes.

$ sudo systemctl reload nginx

Now if you open browser and go to https://example.com/rspamd/ you will see an authentication screen that prompts for your password. Enter the password saved in step 4 to proceed to Rspamd web interface.

That’s it. In this article, we have learnt how to install and configure Rspamd in Ubuntu. You may customize the above configuration as per your requirement. You can also integrate Rspamd with other software such as Postfix

Also read:

How to Change Wifi Password Via Ubuntu Terminal
How to Set JAVA_HOME in Ubuntu
How to Create Large File in Linux
How to Find JDK Path in Ubuntu
How to Get Length of List in Django Template

Leave a Reply

Your email address will not be published. Required fields are marked *