ufw導入・設定手順書
1. 次のコマンドを実行する。
$ sudo apt install ufw
特定のポートのみパケットを受け付けるようにする(例えば80番ポート、443番ポート、2222番ポートのみ)
1. 次のコマンドを実行する。
$ sudo ufw allow 80
$ sudo ufw allow 443
$ sudo ufw allow 2222
上記3つとも、正常な場合、Rules updated Rules updated (v6)と出力される。
$ sudo ufw default DENY # 上記3つが正常に実行されていることを確認してから最後に実行する
ufwを起動し、自動起動を有効化する。
1. 次のコマンドを実行する。
$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)?と聞かれた場合はyを入力してEnterキーを押す。
正常な場合、Firewall is active and enabled on system startupと出力されて終了する。
$ sudo systemctl enable ufw
正常な場合、Synchronizing state of ufw.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable ufwと出力されて終了する。
2. 次のコマンドを実行し、正常に起動しているか確認する。
$ sudo ufw status
正常な場合、次のような出力を得られる。
code:txt
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
80 ALLOW IN Anywhere
443 ALLOW IN Anywhere
2222 ALLOW IN Anywhere
80 (v6) ALLOW IN Anywhere (v6)
443 (v6) ALLOW IN Anywhere (v6)
2222 (v6) ALLOW IN Anywhere (v6)
参考にした資料