ファイヤーウォール(ufw)
https://raspida.com/firewall4raspbian-ufw を参考にファイヤーウォールを設定していきます。
もっとも、ルータで外部からの接続ポートを制限しているので、あまり変わりません。逆に、外部にサービスする際は、ルータのポート開放とファイヤーウォールの開放と両方やらなければならず、手間がかかることになります。
しかしながら、堅牢なルータであれば心配ないかもしれませんが、民生用のルータをそこまで信用してもいいのかどうか疑問です。特に古いルータを使っているので尚更です。
インストール
$ sudo apt-get install -y ufw
設定
コマンドで設定していきます。まず、ファイヤーウォールは動いていない状態で設定しますので、確認します。
$ sudo ufw status
Status: inactive
inactive であれば、動いていないので、設定していきます。
全拒否
はじめに全てのポートを拒否します。
$ sudo ufw default deny
Default incoming policy changed to 'deny’
(be sure to update your rules accordingly)
必要なポートのみ許可していく
次に必要なポートだけ、許可していきます。外部から接続が必要なポートを列挙します。
- 22: ssh
- 80, 443: Apache(http, https)
- 53: dns
- 3306: MariaDB
- 11334: Rspmd
- 25,465,587,993, 995 : postfix(smtp, smtps, imaps, pop3s)
- 123: ntp
もし、この中で、localhost のみでサービスをするものは許可しなくてもいいです。localhost 以外へサービスするポートについて許可していきます。
$ sudo ufw allow 22
Rules updated
Rules updated (v6)
$ sudo ufw allow 25
Rules updated
Rules updated (v6)
$ sudo ufw allow 53
Rules updated
Rules updated (v6)
$ sudo ufw allow 80
Rules updated
Rules updated (v6)
$ sudo ufw allow 123
Rules updated
Rules updated (v6)
$ sudo ufw allow 443
Rules updated
Rules updated (v6)
$ sudo ufw allow 465
Rules updated
Rules updated (v6)
$ sudo ufw allow 587
Rules updated
Rules updated (v6)
$ sudo ufw allow 993
Rules updated
Rules updated (v6)
$ sudo ufw allow 995
Rules updated
Rules updated (v6)
$ sudo ufw allow 3306
Rules updated
Rules updated (v6)
$ sudo ufw allow 11334
Rules updated
Rules updated (v6)
フィやーウォールの起動
$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
確認メッセージが出ます。y で有効になります。
確認
$ sudo ufw status numbered
Status: active
To Action From
-- ------ ----
[ 1] 22 ALLOW IN Anywhere
[ 2] 25 ALLOW IN Anywhere
[ 3] 53 ALLOW IN Anywhere
[ 4] 80 ALLOW IN Anywhere
[ 5] 123 ALLOW IN Anywhere
[ 6] 443 ALLOW IN Anywhere
[ 7] 465 ALLOW IN Anywhere
[ 8] 587 ALLOW IN Anywhere
[ 9] 993 ALLOW IN Anywhere
[10] 995 ALLOW IN Anywhere
[11] 3306 ALLOW IN Anywhere
[12] 11334 ALLOW IN Anywhere
[13] 22 (v6) ALLOW IN Anywhere (v6)
[14] 25 (v6) ALLOW IN Anywhere (v6)
[15] 53 (v6) ALLOW IN Anywhere (v6)
[16] 80 (v6) ALLOW IN Anywhere (v6)
[17] 123 (v6) ALLOW IN Anywhere (v6)
[18] 443 (v6) ALLOW IN Anywhere (v6)
[19] 465 (v6) ALLOW IN Anywhere (v6)
[20] 587 (v6) ALLOW IN Anywhere (v6)
[21] 993 (v6) ALLOW IN Anywhere (v6)
[22] 995 (v6) ALLOW IN Anywhere (v6)
[23] 3306 (v6) ALLOW IN Anywhere (v6)
[24] 11334 (v6) ALLOW IN Anywhere (v6)
その他
ルールの削除
$ sudo ufw delete ルール番号
ファイヤーウォールを停止する
$ sudo ufw disable
ネットワークを指定して許可する
内部ネットワークにだけ許可してそれ以外の外部からは接続させない場合は以下のようにします。
$ sudo ufw allow from 192.168.0.0/24 to any port ポート番号
ディスカッション
コメント一覧
まだ、コメントがありません