(Plesk für Linux) Die Plesk Firewall
Inhalt: 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.
Vorsicht: 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.
Voraussetzungen
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
Standardmäßig besteht die Konfiguration der Plesk Firewall aus Richtlinien und Regeln. Die Richtlinien sind sehr weitgefächert und betreffen je nach Richtlinie alle Verbindungen zum oder vom Server. Sie können zum Beispiel die Systemrichtlinie für eingehenden Traffic verwenden (zu finden unter Tools & Einstellungen > Firewall), um alle eingehenden Verbindungen zum Server zu blockieren. Regeln sind enger definiert und betreffen eingehende Verbindungen zu einzelnen Plesk Diensten wie SMTP oder MySQL.
Beachten Sie, dass Regeln Vorrang vor Richtlinien haben. Wenn eine allgemeine Richtlinie zum Beispiel den kompletten eingehenden Traffic ablehnt, eine Regel jedoch den eingehenden Traffic für eine bestimmte IP erlaubt, hat die Regel Vorrang. Mit diesem Mechanismus können Sie die Sicherheit des Servers ganz einfach auflockern oder straffen. Wenn Sie zum Beispiel die Richtlinien so einrichten, dass alle Verbindungen zum und vom Server blockiert werden, einige wenige IP-Adressen oder Ports jedoch davon ausgenommen sind, erhöhen Sie die Sicherheit. Einige Anwendungen funktionieren aber möglicherweise nicht aufgrund der Netzwerkeinschränkungen. Wenn Sie im Gegensatz dazu alle Verbindungen standardmäßig zulassen und Regeln zum Blockieren einzelner Dienste oder individueller IP-Adressen einsetzen, ist Ihr Server zwar nicht so sicher, aber Sie vergewissern sich, dass es zu keinen Verbindungsproblemen kommt. Probieren Sie verschiedene Varianten aus, bis Sie eine zufriedenstellende Balance zwischen Nutzbarkeit und Sicherheit gefunden haben.
Für die Verwaltung der Firewall stehen Ihnen zwei Optionen zur Verfügung:
- Einstellungen der Standardrichtlinien und -regeln ändern
- Benutzerdefinierte Regeln erstellen
Um die Einstellungen der Standardrichtlinien und -regeln zu ändern, gehen Sie zu Tools & Einstellungen > Firewall (in der Gruppe Sicherheit) und klicken Sie auf Firewallregelverwaltung aktivieren. Bestätigen Sie die Aktivierung der Regelverwaltung, warten Sie, bis die Änderungen angewendet wurden, und klicken Sie anschließend auf Plesk Firewallregeln modifizieren. Klicken Sie auf die Regel oder Richtlinie, die Sie ändern möchten. Sie können über eine Richtlinie festlegen, dass Verbindungen zugelassen oder abgelehnt werden. Über eine Regel können Sie einstellen, dass Verbindungen erlaubt bzw. nicht zugelassen werden oder Verbindungen nur von bestimmten Adressen zugelassen und die restlichen Verbindungen abgelehnt werden. Nachdem Sie alle gewünschten Änderungen durchgeführt haben, klicken Sie auf Änderungen übernehmen, um den neuen Regelsatz zu aktivieren. Klicken Sie auf Änderungen verwerfen, um die Änderungen zurückzusetzen.
Um eine benutzerdefinierte Regel hinzuzufügen, aktivieren Sie die Verwaltung von Firewallregeln wie oben beschrieben und klicken Sie auf Benutzerdefinierte Regel hinzufügen. Benutzerdefinierte Regeln sind flexibler als Standardregeln und können so konfiguriert werden, dass eingehende, ausgehende oder weiterleitende Verbindungen zu bzw. von bestimmten Ports oder IP-Adressen zugelassen oder abgelehnt werden. Nachdem Sie eine oder mehrere benutzerdefinierte Regeln hinzugefügt haben, klicken Sie auf Änderungen übernehmen, um die Regeln zum Regelsatz hinzuzufügen. Klicken Sie auf Änderungen verwerfen, um die Änderungen zurückzusetzen. Wenn Sie zu einem späteren Zeitpunkt eine oder mehrere benutzerdefinierte Regeln entfernen möchten, wählen Sie die entsprechenden Kontrollkästchen aus, klicken Sie auf Löschen, bestätigen Sie den Löschvorgang und klicken Sie anschließend auf Änderungen übernehmen, um die ausgewählten Regeln aus dem Regelsatz zu entfernen.
Wenn Sie benutzerdefinierte Regeln erstellen, vergewissern Sie sich, keine Verbindungen zu von Plesk Diensten verwendeten Ports irrtümlich zu blockieren.
Bemerkung: Wenn Sie Docker-Container verwenden, werden die Docker-Firewallregeln nicht zu den Firewallregeln von Plesk hinzugefügt.
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
- Anmeldung bei Plesk.
- Gehen Sie zu Tools & Einstellungen > Firewall (unter „Sicherheit“).
- 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
oder
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.
Bemerkung: The command may finish with a
Set cannot be destroyed
warning. The warning can be safely ignored. -
Gehen Sie zu Tools & Einstellungen > Firewall (unter „Sicherheit“).
-
Click Apply Changes, and then click Apply.
Bemerkung: 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.
- Gehen Sie zu Tools & Einstellungen > Firewall (unter „Sicherheit“).
- 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.
- Gehen Sie zu Tools & Einstellungen > Firewall (unter „Sicherheit“).
- 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
oder
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.