(Plesk pour Linux) Le pare-feu de Plesk
Résumé: The Plesk firewall is a tool you can use to improve the security of your Plesk for Linux server by restricting network connections to and/or from the server.
In this topic, you will learn how to add and remove firewall rules and policies, how to block incoming connections from specific countries, and also how to export and import firewall rules to easily replicate firewall configuration between servers.
Prudence: Both the Plesk firewall and firewalld are tools for managing the iptables firewall. Using both tools simultaneously can result in conflicts and in ports required for Plesk to operate being closed. We recommend only using one tool at a time.
Prérequis
Before you can begin, the « Firewall » extension must be installed on the server. If it is not, install the extension from the Extensions Catalog.
Managing Firewall Rules and Policies
Par défaut, la configuration du pare-feu de Plesk se compose de politiques et de règles. Les politiques couvrent de nombreux aspects et affectent toutes les connexions depuis ou vers le serveur, selon la politique elle-même. Par exemple, vous pouvez utiliser la politique System policy for incoming traffic (disponible dans Outils & Paramètres > Pare-feu) pour bloquer complètement toutes les connexions entrantes vers le serveur. Les règles sont plus précises et gouvernent les connexions entrantes vers des services individuels de Plesk, comme SMTP ou MySQL.
Notez que les règles écrasent les politiques. Par exemple : si une politique globale refuse tout trafic entrant et si une règle autorise le trafic entrant depuis une adresse IP spécifique, la règle est prioritaire. Vous pouvez utiliser ce mécanisme pour renforcer ou assouplir facilement la sécurité du serveur. Par exemple : configurer des politiques pour interdire toutes les connexions depuis et vers le serveur sauf pour quelques adresses IP et ports permet d’améliorer la sécurité. Toutefois, certaines applications risquent de ne pas fonctionner correctement en raison de restrictions du réseau. À l’inverse, autoriser toutes les connexions par défaut et utiliser des règles pour bloquer l’accès vers des services individuels ou depuis des adresses IP individuelles réduit la sécurité du serveur mais évite les problèmes de connexion. Faites vos propres tests pour déterminer le meilleur compromis entre usage et sécurité.
Vous pouvez gérer le pare-feu de deux manières :
- Modifier les paramètres des politiques et règles par défaut.
- Créer des règles personnalisées.
Pour modifier les paramètres des politiques et règles par défaut, allez dans Outils & Paramètres > Pare-feu (groupe Sécurité) et cliquez sur Activer la gestion des règles du pare-feu. Confirmez l’activation de la gestion des règles, patientez jusqu’à l’application des modifications, puis cliquez sur Modifier les règles du pare-feu Plesk. Cliquez sur la règle ou la politique que vous voulez modifier. Vous pouvez définir une politique pour autoriser ou refuser des connexions ainsi qu’une règle pour autoriser ou refuser des connexions, ou autoriser les connexions depuis des adresses indiquées uniquement et refuser toutes les autres. Une fois que vous avez procédé aux modifications, cliquez sur Appliquer les changements pour faire entrer en vigueur les modifications ou sur Abandonner les changements pour tout annuler.
Pour ajouter une règle personnalisée, activez la gestion des règles comme indiqué ci-dessus et cliquez sur Ajouter une règle personnalisée. Les règles personnalisée sont plus flexibles que les règles standard et peuvent être configurées pour autoriser ou refuser toutes les connexions entrantes, sortantes ou transférées depuis ou vers un port ou une adresse IP spécifique. Une fois que vous avez ajouté une ou plusieurs règles personnalisées, cliquez sur Appliquer les changements pour les appliquer aux jeux de règles ou sur Abandonner les changements pour tout annuler. Si ultérieurement vous décidez de supprimer une ou plusieurs règles personnalisées, cochez les cases correspondantes. Cliquez sur Supprimer, confirmez la suppression et cliquez sur Appliquer les changements pour supprimer les règles du jeu de règles.
Lorsque vous créez des règles personnalisées, veillez à ne pas bloquer par inadvertance des ports utilisés par les services Plesk.
Note: si vous utilisez des conteneurs Docker, les règles du pare-feu Docker ne sont pas ajoutées aux règles du pare-feu Plesk.
Country Blocking
You can use the Plesk firewall to block access to or from IP addresses belonging to a particular country.
Blocking access from a specific country
- Connectez-vous à Plesk.
- Allez dans Outils & Paramètres > Pare-feu (sous « Sécurité »).
- Click the « Firewall protection » toggle button so that it shows “Enabled”. If firewall protection is already enabled, skip this step.
- Click the
button.
- (Optional) Give your rule a name.
- Set « Action » to « Deny ».
- Under « Sources », enter the two letter ISO 3166 country code of the country you want to block (for example, to block all incoming connections from Afghanistan, enter AF).
- (Optional) Click « Add one more », and repeat the previous step to block an additional country. You can block as many countries as you want.
- Click Save once you have added all countries you want to block.
- Click Apply Changes, and then click Apply.
Once the firewall configuration has been applied, all incoming connections to your server from the blocked country or countries will be denied.
By default, Plesk uses the free « IP to Country Lite » database from DB-IP. You can instead use a free or paid database from MaxMind. Before you can do so, you need to obtain a free or paid license from MaxMind and receive your license key.
Switching to the paid GeoIP2 database
-
Add the following lines to the panel.ini file:
[ext-firewall] geoipDataSource = maxmind-lite
to use the free GeoLite2 database, or
[ext-firewall] geoipDataSource = maxmind
to use the paid GeoIP2 database.
-
Log in to the server via SSH, and then run the following command:
LICENSE_KEY=<enter your license key here> plesk sbin modules/firewall/ipsets --configure --data-source maxmind-lite --force
ou
LICENSE_KEY=<enter your license key here> plesk sbin modules/firewall/ipsets --configure --data-source maxmind --force
to use the free or paid database from MaxMind, respectively.
Note: The command may finish with a
Set cannot be destroyed
warning. The warning can be safely ignored. -
Allez dans Outils & Paramètres > Pare-feu (sous « Sécurité »).
-
Click Apply Changes, and then click Apply.
Note: If the Apply Changes button is missing, create a new firewall rule to trigger the ability to apply changes. You can remove that rule afterwards.
Once the firewall configuration has been applied, the GeoIP2 database will be used instead of GeoLite2.
To switch back to the free database from DB-IP, remove the geoipDataSource = maxmind-lite
or geoipDataSource = maxmind
line from the panel.ini
file, and then reapply the firewall configuration.
Importing and Exporting Firewall Configuration
You may want to duplicate one Plesk for Linux server’s firewall configuration on other Plesk for Linux servers. The easiest way to do so is to export the firewall configuration to a file, and then to import it on each of those Plesk for Linux servers. You can import and export the firewall configuration both via the graphical interface and the command line.
Exporting the firewall configuration via the GUI
- Log in to Plesk on the server whose firewall configuration you want to copy.
- Allez dans Outils & Paramètres > Pare-feu (sous « Sécurité »).
- Click Export.
The firewall configuration will be saved to a .json
file. You can find it in your browser’s downloads directory.
Importing the firewall configuration via the GUI
- Log in to Plesk on a server you want to copy another server’s firewall configuration to.
- Allez dans Outils & Paramètres > Pare-feu (sous « Sécurité »).
- Click the « Firewall protection » toggle button so that it shows “Enabled”, and then click Apply. If firewall protection is already enabled, skip this step.
- Click Import, and then locate the
.json
file exported on the server whose firewall configuration you want to copy.
The firewall configuration from the file will be applied.
Exporting the firewall configuration via the CLI
-
Log in via SSH to the server whose firewall configuration you want to copy.
-
Run the following command to export the firewall configuration:
plesk ext firewall --export > rules.json
You can give the file any name you want, « rules.json » is just an example,
The firewall configuration will be saved to the specified file.
Importing the firewall configuration via the CLI
-
Log in via SSH to a server you want to copy another server’s firewall configuration to. You need to open two separate SSH sessions to import the firewall configuration.
-
In the first SSH session, run the following command to enable firewall protection. If firewall protection is already enabled, skip this step.
plesk ext firewall --enable
-
In the second SSH session, run the following command to confirm firewall protection. If firewall protection is already enabled, skip this step.
plesk ext firewall --confirm
-
In the first SSH session, run the following command to import and apply the firewall configuration:
plesk ext firewall --import -config <the file's URL or local path> && plesk ext firewall --apply
For example
plesk ext firewall --import -config https://example.com/rules.json && plesk ext firewall --apply
ou
plesk ext firewall --import -config /tmp/rules.json && plesk ext firewall --apply
-
In the second SSH session, run the following command to confirm the imported firewall configuration.
plesk ext firewall --confirm
The firewall configuration from the file will be applied to the server.