(Plesk for Linux)Plesk ファイアウォール
概要: Plesk ファイアウォールは、Plesk for Linux サーバとのネットワーク接続を制限することでサーバのセキュリティを強化するためのツールです。
このトピックでは、ファイアウォールルールとポリシーの追加・削除方法、特定の国からの接続をブロックする方法、ファイアウォールルールをエクスポート・インポートしてサーバ間でファイアウォール構成を簡単に複製する方法を学びます。
ご用心: Plesk ファイアウォールと firewalld は、いずれも iptables ファイアウォールを管理するためのツールです。両ツールを同時に使用すると競合が発生し、Plesk が動作するために必要なポートが閉じられてしまいます。一度にいずれか 1 つのツールだけ使用することをお勧めします。
前提条件
開始する前に、サーバに "Firewall" 拡張をインストールする必要があります。インストールされていない場合は拡張カタログから拡張をインストールする必要があります。
ファイアウォールルールとポリシーを管理する
By default, the Plesk firewall configuration consists of policies and rules:
- Policies are broad in scope and affect all connections to or from the server, depending on the policy itself. For example, you can use "System policy for incoming traffic" to completely block all incoming connections to the server.
- Rules are narrower in scope and govern incoming connections to individual Plesk services, such as SMTP or MySQL/MariaDB.
Rules override policies. For example, if the global policy is to deny all incoming traffic, but a rule allows incoming traffic from a specific IP, the rule takes precedence. You can use this mechanism to tighten or relax the security of the server.
For example, setting up the policies to forbid all connections to and from the server except for a few allowed IP addresses or ports will result in improved security, but some applications may not be able to work due to the network restrictions. Conversely, allowing all connections by default and using rules to block access to individual services or from individual IP addresses will make your server less secure, but will ensure that you do not run into connection issues. Experiment to find the optimal trade-off between usability and security.
ファイアウォールは以下の 2 通りの方法で管理できます。
- Modifying existing policies and rules, including the default ones.
- Creating and removing custom rules.
Modifying an existing policy or rule:
- Plesk にログインします。
- [ツールと設定] > [ファイアウォール]([セキュリティ]の下)に移動します。
- Click the "Firewall protection" toggle button so that it shows "Enabled". If firewall protection is already enabled, skip this step.
- Click the policy or rule you want to modify.
- Make the desired changes, click Save, click Apply Changes, and then click Apply.
The changes to the firewall configuration are now in effect.
Creating a custom rule:
- Plesk にログインします。
- [ツールと設定] > [ファイアウォール]([セキュリティ]の下)に移動します。
- Click the "Firewall protection" toggle button so that it shows "Enabled". If firewall protection is already enabled, skip this step.
- ボタンをクリックします。
- (オプション)ルールに名前を付けます。
- Configure the rule. For example, to block all incoming connections to the SSH service from IP address 198.51.100.1 (assuming the default SSH port is being used), set "Match direction" to "Incoming", set "Action" to "Deny", set "Port" to "TCP 22", and then enter "198.51.100.1" in the "Sources" field.
- Once you have configured the rule, click Save, click Apply Changes, and then click Apply.
The changes to the firewall configuration are now in effect. When creating custom rules, be careful not to block connections to ports used by Plesk services by mistake.
注釈: Docker コンテナ を使用している場合、Plesk ファイアウォールルールに Docker ファイアウォールルールが追加されません。
Removing custom rules:
- Plesk にログインします。
- [ツールと設定] > [ファイアウォール]([セキュリティ]の下)に移動します。
- Click the "Firewall protection" toggle button so that it shows "Enabled". If firewall protection is already enabled, skip this step.
- Select one or more custom rules you want to remove. Only custom rules can be removed.
- Click Remove, click Yes, remove, click Apply Changes, and then click Apply.
The changes to the firewall configuration are now in effect.
国別ブロック
Plesk ファイアウォールを使用して、特定の国に属する IP アドレスとのアクセスをブロックできます。
特定の国からのアクセスをブロックする:
- Plesk にログインします。
- [ツールと設定] > [ファイアウォール]([セキュリティ]の下)に移動します。
- Click the "Firewall protection" toggle button so that it shows "Enabled". If firewall protection is already enabled, skip this step.
- ボタンをクリックします。
- (オプション)ルールに名前を付けます。
- 「アクション」を「拒否」に設定します。
- [ソース]の下に、ブロックする国の 2 桁の ISO 3166 国コードを入力します(たとえば、アフガニスタンからの接続をすべてブロックする場合は AF と入力します)。
- (オプション)[もう 1 つ追加]をクリックして前の工程を繰り返すと、追加の国をブロックできます。国は必要な数だけブロックできます。
- ブロックする国をすべて追加したら、[保存]をクリックします。
- [変更を適用]をクリックして、[適用]をクリックします。
ファイアウォールの構成が適用された後は、ブロック対象の国からサーバへの接続がすべて拒否されるようになります。
デフォルトで、Plesk は DB-IP の無料データベース「IP to Country Lite」を使用します。代わりに MaxMind の無料または有料のデータベースを使用することもできます。その場合、事前に MaxMind から無料または有料ライセンスを取得してライセンスキーを受け取っておく必要があります。
有料の GeoIP2 データベースに切り替える:
-
panel.ini ファイルに以下の行を追加します。
[ext-firewall] geoipDataSource = maxmind-lite
無料の GeoLite2 データベースを使用する場合
[ext-firewall] geoipDataSource = maxmind
有料の GeoIP2 データベースを使用する場合
-
サーバに SSH ログインして、以下のコマンドを実行します。
LICENSE_KEY=<enter your license key here> plesk sbin modules/firewall/ipsets --configure --data-source maxmind-lite --force
または
LICENSE_KEY=<enter your license key here> plesk sbin modules/firewall/ipsets --configure --data-source maxmind --force
順に、MaxMind の無料または有料のデータベースを使用する場合
注釈: コマンドが
Set cannot be destroyed
という警告で終了する場合がありますが、この警告は無視しても問題ありません。 -
[ツールと設定] > [ファイアウォール]([セキュリティ]の下)に移動します。
-
[変更を適用]をクリックして、[適用]をクリックします。
注釈: [変更を適用]ボタンがない場合、変更の適用を軌道するための新しいファイアウォールルールを作成します。このルールは後で削除できます。
ファイアウォールの構成が適用されたら、GeoIP2 データベースが GeoLite2 の代わりに使用されるようになります。
DB-IP の無料データベースに戻すには、panel.ini
ファイルから geoipDataSource = maxmind-lite
または geoipDataSource = maxmind
の行を削除してから、ファイアウォールの構成をもう一度適用します。
ファイアウォール構成をインポートまたはエクスポートする
Plesk for Linux サーバのファイアウォール構成を別の Plesk for Linux サーバで複製することができます。最も簡単なのは、ファイアウォール構成をファイルにエクスポートして、それぞれの Plesk for Linux サーバにインポートする方法です。ファイアウォール構成のインポートとエクスポートは、グラフィカルインターフェース経由でもコマンドライン経由でも可能です。
GUI 経由でファイアウォール構成をエクスポートする:
- ファイアウォール構成をコピーしたいサーバで Plesk にログインします。
- [ツールと設定] > [ファイアウォール]([セキュリティ]の下)に移動します。
- [ファイアウォール保護]のトグルボタンをクリックして[有効]を表示させてから、[適用]をクリックします。ファイアウォール保護を既に有効にしている場合、この手順はスキップしてください。
- [エクスポート]をクリックします。
ファイアウォール構成が .json
ファイルに保存されます。このファイルはブラウザのダウンロードディレクトリで見つけることができます。
GUI 経由でファイアウォール構成をインポートする:
- 別のサーバからファイアウォール構成をコピーしたいサーバで Plesk にログインします。
- [ツールと設定] > [ファイアウォール]([セキュリティ]の下)に移動します。
- [ファイアウォール保護]のトグルボタンをクリックして[有効]を表示させてから、[適用]をクリックします。ファイアウォール保護を既に有効にしている場合、この手順はスキップしてください。
-
[インポート]をクリックして、ファイアウォール構成のコピー元サーバからエクスポートされた
.json
ファイルを探します。
このファイルからファイアウォール構成が適用されます。
CLI 経由でファイアウォール構成をエクスポートする:
-
ファイアウォール構成をコピーしたいサーバに SSH 経由でログインします。
-
以下のコマンドを実行してファイアウォール構成をエクスポートします。
plesk ext firewall --export > rules.json
ファイルの名前は自由に付けられます。「rules.json」は一例です。
指定したファイルにファイアウォール構成が保存されます。
CLI 経由でファイアウォール構成をインポートする:
-
他のサーバからファイアウォール構成をコピーしたいサーバに SSH 経由でログインします。ファイアウォール構成をインポートするためには、2 つの別々の SSH セッションを開く必要があります。
-
最初の SSH セッションでは、以下のコマンドを実行してファイアウォールによる保護を有効にします。既に有効になっている場合、この手順はスキップしてください。
plesk ext firewall --enable
-
2 番目の SSH セッションでは、以下のコマンドを実行してファイアウォールによる保護を確認します。既に有効になっている場合、この手順はスキップしてください。
plesk ext firewall --confirm
-
最初の SSH セッションで、以下のコマンドを実行してファイアウォール構成をインポートし、適用します。
plesk ext firewall --import -config <the file's URL or local path> && plesk ext firewall --apply
例:
plesk ext firewall --import -config https://example.com/rules.json && plesk ext firewall --apply
または
plesk ext firewall --import -config /tmp/rules.json && plesk ext firewall --apply
-
Verify that you can connect to the server via SSH after applying the new firewall configuration. If you can, in the second SSH session, run the following command to confirm the imported firewall configuration.
plesk ext firewall --confirm
注釈: If you do not confirm the imported firewall configuration within 60 seconds of running the
plesk ext firewall --apply
command, the changes you made will be rolled back automatically, and the previous firewall configuration will be restored.
このファイルのファイアウォール構成がサーバに適用されます。