YANO's digital garage

Copyright ©YANO All rights reserved. https://www.bravotouring.com/~yano/

Last-modified: 2024-04-17 (水)


[一語一絵/IT系]

UFW(Uncomplicated Firewall) / 2013-01-17 (木)

GT110bでもファイアーウォールはnx9030からの(つまりCentOSの)/etc/iptables.rulesな設定を引きずってきたが、ようやくubuntuの流儀に従ってUFW(Uncomplicated Firewall)ベースの設定で整理した。

基本的には入側DENY/出側ALLOWにdefault設定し、入側の許可ルールを「sudo ufw allow ~」で追加していくだけで、sshdomainなど/etc/servicesに定義済みのポートについてはその定義名を、その他のサービスやアプリケーション毎の設定については/etc/ufw/applications.d/配下に定義して「sudo ufw app list」で表示される識別子を指定すれば良い。

さくらのVPSで解放する必要があるのはDNSとWebとsshとメールだけ。 まずは/etc/ufw/applications.d/postfixにsmtpsの定義を追加し、

[Postfix]
title=Mail server (SMTP)
description=Postfix is a high-performance mail transport agent
ports=25/tcp

[Postfix Submission]
title=Mail server (Submission)
description=Postfix is a high-performance mail transport agent
ports=587/tcp

[Postfix Secure]
title=Mail server (SSL)
description=Postfix is a high-performance mail transport agent
ports=465/tcp
あとは、以下の様な感じで。
yano@sakura_vps:~$ sudo ufw status
状態: 非アクティブ
yano@sakura_vps:~$ sudo ufw default DENY incoming
Default incoming policy changed to 'deny'
(適用したい内容に基づいて必ずルールを更新してください)
yano@sakura_vps:~$ sudo ufw default ALLOW outgoing
Default outgoing policy changed to 'allow'
(適用したい内容に基づいて必ずルールを更新してください)
yano@sakura_vps:~$ sudo ufw app list
存在するアプリケーション:
  Apache
  Apache Full
  Apache Secure
  Dovecot IMAP
  Dovecot POP3
  Dovecot Secure IMAP
  Dovecot Secure POP3
  OpenSSH
  Postfix
  Postfix Submission
  Postfix Secure
yano@sakura_vps:~$ sudo ufw allow ssh
ルールをアップデートしました
yano@sakura_vps:~$ sudo ufw allow domain
ルールをアップデートしました
yano@sakura_vps:~$ sudo ufw allow "Postfix"
ルールをアップデートしました
yano@sakura_vps:~$ sudo ufw allow "Postfix Submission"
ルールをアップデートしました
yano@sakura_vps:~$ sudo ufw allow "Postfix Secure"
ルールをアップデートしました
yano@sakura_vps:~$ sudo ufw allow "Dovecot POP3"
ルールをアップデートしました
yano@sakura_vps:~$ sudo ufw allow "Dovecot Secure POP3"
ルールをアップデートしました
yano@sakura_vps:~$ sudo ufw allow "Apache Full"
ルールをアップデートしました
yano@sakura_vps:~$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
ファイアウォールはアクティブかつシステムの起動時に有効化されます。
yano@sakura_vps:~$ sudo ufw status
状態: アクティブ

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere
53                         ALLOW       Anywhere
Postfix                    ALLOW       Anywhere
Postfix Submission         ALLOW       Anywhere
Postfix Secure             ALLOW       Anywhere
Dovecot POP3               ALLOW       Anywhere
Dovecot Secure POP3        ALLOW       Anywhere
Apache Full                ALLOW       Anywhere

yano@sakura_vps:~$

GT110bについてはbootps,samba,epgrec,mediatomb,mt-daapdを追加する必要があるので、以下の様にそれぞれの定義ファイルを用意する。 /etc/ufw/applications.d/epgrec

yano@GT110b:~$ cat /etc/ufw/applications.d/epgrec
[epgrec]
title=epgrec
description=epgrec tv recording server.
ports=8989/tcp
/etc/ufw/applications.d/mediatomb
yano@GT110b:~$ cat /etc/ufw/applications.d/mediatomb
[mediatomb]
title=mediatomb
description=mediatomb DLNA server.
ports=49152,49153,49154/tcp
/etc/ufw/applications.d/mt-daapd
yano@GT110b:~$ cat /etc/ufw/applications.d/mt-daapd
[mt-daapd]
title=mt-daapd
description=mt-daapd (firefly/itunes) server.
ports=3689/tcp
なお「UPnP discovery」については/etc/ufw/applications.d/mediatombでマルチキャストアドレスを条件定義できなかったので、ufwコマンドで個別に設定する。
yano@GT110b:~$ sudo ufw status
状態: 非アクティブ
yano@GT110b:~$ sudo ufw default DENY incoming
Default incoming policy changed to 'deny'
(適用したい内容に基づいて必ずルールを更新してください)
yano@GT110b:~$ sudo ufw default ALLOW outgoing
Default outgoing policy changed to 'allow'
(適用したい内容に基づいて必ずルールを更新してください)
yano@GT110b:~$ sudo ufw app list
存在するアプリケーション:
  Apache
  Apache Full
  Apache Secure
  Dovecot IMAP
  Dovecot POP3
  Dovecot Secure IMAP
  Dovecot Secure POP3
  OpenSSH
  Postfix
  Postfix Submission
  mediatomb
  mt-daapd
yano@GT110b:~$ sudo ufw allow bootps
ルールをアップデートしました
yano@GT110b:~$ sudo ufw allow domain
ルールをアップデートしました
yano@GT110b:~$ sudo ufw allow ssh
ルールをアップデートしました
yano@GT110b:~$ sudo ufw allow syslog
ルールをアップデートしました
yano@GT110b:~$ sudo ufw allow "Apache Full"
ルールをアップデートしました
yano@GT110b:~$ sudo ufw allow samba
ルールをアップデートしました
yano@GT110b:~$ sudo ufw allow epgrec
ルールをアップデートしました
yano@GT110b:~$ sudo ufw allow mediatomb
ルールをアップデートしました
yano@GT110b:~$ # Setting for UPnP discovery
yano@GT110b:~$ sudo ufw allow proto udp from any port 1900 to 239.0.0.0/8
ルールをアップデートしました
yano@GT110b:~$ sudo ufw allow mt-daapd
ルールをアップデートしました
yano@GT110b:~$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
ファイアウォールはアクティブかつシステムの起動時に有効化されます。

追加した結果は/lib/ufw/user.rulesに集約される。

ルールの削除は

yano@GT110b:~$ sudo ufw delete allow "Apache Full"
で行い、
yano@GT110b:~$ sudo ufw reload
で実際の動作に反映する。 コマンド一覧(ヘルプ)は
yano@GT110b:~$ sudo ufw help

Usage: ufw COMMAND

Commands:
enable                          enables the firewall
disable                         disables the firewall
default ARG                     set default policy
logging LEVEL                   set logging to LEVEL
allow ARGS                      add allow rule
deny ARGS                       add deny rule
reject ARGS                     add reject rule
limit ARGS                      add limit rule
delete RULE|NUM                 delete RULE
insert NUM RULE                 insert RULE at NUM
reset                           reset firewall
status                          show firewall status
status numbered                 show firewall status as numbered list of RULES
status verbose                  show verbose firewall status
show ARG                        show firewall report
version                         display version information

Application profile commands:
app list                        list application profiles
app info PROFILE                show information on PROFILE
app update PROFILE              update PROFILE
app default ARG                 set default application policy

【参照】
●Official Ubuntu Documentation https://help.ubuntu.com/
UFW
●Ubuntu Japanese Wiki https://wiki.ubuntulinux.jp/
UbuntuTips
Ufw
DLNAserver - MediaTomb
Firefly - mt-daapd