[[PageOutline]] = ufw = * Uncomplicated Firewall * iptablesのラッパー * /usr/sbin/ufw: python script text executable * [https://help.ubuntu.com/8.04/serverguide/C/firewall.html Firewall] - 8.04 * [https://help.ubuntu.com/10.04/serverguide/C/firewall.html Firewall] - 10.04 == 設定ファイル == * /etc/default/ufw * ip6tablesのon/off、「ufw default deny/allow」による設定(iptables -P INPUT ACCEPT/DROPに対応)、下の/etc/ufw/sysctl.confの指定など * /etc/ufw/ufw.conf * ufw の 有効/無効 * /etc/ufw/sysctl.conf * sysctl settings * /etc/ufw/*.rules * uwf コマンドで変更できない設定 * iptables-save/restore 形式 * /var/lib/ufw/user*.rules * uwf コマンドで変更できる設定 * iptables-save/restore 形式 * 設定ファイルの直接編集については => source:/lab.git/TipAndDoc/iptables/ufw === chain の適用順 === 1. /etc/ufw/before(6).rules にあるchainが適用される 1. /var/lib/ufw/user(6).rules にあるchainが適用される 1. /etc/ufw/after(6).rules にあるchainが適用される ==== /etc/init.d/ufw ==== * 大まかな流れ (IPv6=noの場合) 1. modprobe $IPT_MODULES <- /etc/default/ufw 1. iptables -F, iptables -X で flush 1. /etc/default/ufw から iptables -P INPUT/OUTPUT/FORWARD 1. iptables -N ufw-before-* * iptables -A INPUT/* ufw-before-* * iptables-restore < /etc/ufw/before.rules 1. iptables -N ufw-user-* * iptables -A ufw-before-* ufw-user-* * iptables-restore < /var/lib/ufw/user.rules * iptables -A ufw-user-* -j RETURN は user.rules で定義されているので、/etc/init.d/ufwでは行わない (iptables-restoreで行われる) 1. iptables -A ufw-before-* -j RETURN 1. iptables -N ufw-after-* * iptables -A INPUT/* ufw-after-* * iptables-restore < /etc/ufw/after.rules 1. iptables -A ufw-after-* -j RETURN 1. sysctl $IPT_SYSCTL <- /etc/default/ufw == 設定 == * 細かい設定は [https://help.ubuntu.com/8.04/serverguide/C/firewall.html Firewall] および man ufw * ufw enable していない状態でも、設定自体は出来るが、ufw statusが確認できない (/var/lib/ufw/user*.rules を確認することは出来る) {{{ Firewall not loaded }}} * sudo ufw allow 22; sudo ufw enable; sudo ufw status {{{ Rules updated Firewall started and enabled on system startup Firewall loaded To Action From -- ------ ---- 22:tcp ALLOW Anywhere 22:udp ALLOW Anywhere }}} == 短所 == * --state などの細かい制御は対応してない模様 * /var/lib/ufw/user.rules を直接編集した場合 * 元 (ufw allow 22) {{{ ### tuple ### allow any 22 0.0.0.0/0 any 0.0.0.0/0 -A ufw-user-input -p tcp --dport 22 -j ACCEPT -A ufw-user-input -p udp --dport 22 -j ACCEPT }}} * 直接編集 (see also [http://www.atmarkit.co.jp/flinux/rensai/iptables01/iptables01d.html @IT:ステートフルパケットフィルタを使ったサービスの公開(4/6)]) {{{ -A ufw-user-input -p tcp ! --syn -m state --state NEW -j DROP -A ufw-user-input -p tcp -m state --state NEW,ESTABLISHED,RELATED --dport 22 -j ACCEPT }}} * ufw status がおかしなことになる {{{ To Action From -- ------ ---- Anywhere DENY Anywhere Anywhere ALLOW Anywhere }}} * ufw コマンドでルールを追加すると、直接編集したルールは消去される * filter table以外を/etc/ufw/*.rulesに書くと、ufw startで反映はされるがufw stopで消去されないので設定が累積していく * ~~interfaces pre-upとかに入れるのがよさそう…~~ => スクリプトを作成 => [../iptables#setfilter] == chain tree == * see also [./default] === lucid === * 以下のchainは /lib/ufw/user.rules に記述される {{{ ufw-user-* ufw-before-logging-* ufw-user-logging-* ufw-after-logging-* ufw-logging-deny }}} * filter target tree {{{ INPUT | |----> ufw-before-logging-input | | |<------/ | | |----> ufw-before-input | | | |----> ACCEPT | | | |----> ufw-logging-deny ----> LOG | | | | | | DROP <------------------/ | | | |----> ACCEPT | | | |----> ufw-not-local | | | | |<------| | | | | | |----> ufw-logging-deny ----> LOG | | | | | | DROP <--------------------------/ | | | |----> ACCEPT | | | |----> ufw-user-input | | | | |<------/ | | |<------/ | | |----> ufw-after-input | | | |----> ufw-skip-to-policy-input ----> DROP | | |<------/ | | |----> ufw-after-logging-input | | | LOG | | |<------/ | | |----> ufw-reject-input | | |<------/ | | |----> ufw-track-input | | |<------/ | DROP }}} {{{ FORWARD | |----> ufw-before-logging-forward | | |<------/ | | |----> ufw-before-forward | | | |----> ufw-user-forward | | | | |<------/ | | |<------/ | | |----> ufw-after-forward | | |<------/ | | |----> ufw-after-logging-forward ----> LOG | | |<--------------------------------------/ | | |----> ufw-reject-forward | | |<------/ | DROP }}} {{{ OUTPUT | | |----> ufw-before-logging-output | | | | | | |<------/ | | |----> ufw-before-output | | | |----> ACCEPT | | | |----> ufw-user-output | | | | |<------/ | | |<------/ | | |----> ufw-after-output | | | | | | |<------/ | | |----> ufw-after-logging-output | | | | | | |<------/ | | |----> ufw-reject-output | | | | | | |<------/ | | |----> ufw-track-output | | | |----> ACCEPT | | |<------/ | ACCEPT }}}