wiki:TipAndDoc/network/ufw

ufw

  • Uncomplicated Firewall
    • iptablesのラッパー
    • /usr/sbin/ufw: python script text executable

設定ファイル

  • /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 形式

chain の適用順

  1. /etc/ufw/before(6).rules にあるchainが適用される
  2. /var/lib/ufw/user(6).rules にあるchainが適用される
  3. /etc/ufw/after(6).rules にあるchainが適用される

/etc/init.d/ufw

  • 大まかな流れ (IPv6=noの場合)
    1. modprobe $IPT_MODULES <- /etc/default/ufw
    2. iptables -F, iptables -X で flush
    3. /etc/default/ufw から iptables -P INPUT/OUTPUT/FORWARD
    4. iptables -N ufw-before-*
      • iptables -A INPUT/* ufw-before-*
      • iptables-restore < /etc/ufw/before.rules
    5. 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で行われる)
    6. iptables -A ufw-before-* -j RETURN
    7. iptables -N ufw-after-*
      • iptables -A INPUT/* ufw-after-*
      • iptables-restore < /etc/ufw/after.rules
    8. iptables -A ufw-after-* -j RETURN
    9. sysctl $IPT_SYSCTL <- /etc/default/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 status がおかしなことになる
      To                         Action  From
      --                         ------  ----
      Anywhere                   DENY    Anywhere
      Anywhere                   ALLOW   Anywhere
      
  • ufw コマンドでルールを追加すると、直接編集したルールは消去される
  • filter table以外を/etc/ufw/*.rulesに書くと、ufw startで反映はされるがufw stopで消去されないので設定が累積していく
    • interfaces pre-upとかに入れるのがよさそう… => スクリプトを作成 => iptables

chain tree

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
    
Last modified 10 years ago Last modified on Nov 27, 2013 9:54:12 PM