firewalld

Contents

firewalldについて


firewalldはRedhat系Linuxのバージョン7以降で導入された、旧来のiptablesに代わるファイアウォールサービスである。
L4レベルのフィルタリング機能を持つ。

原則としてホワイトリスト方式での設定を行うが、個別の詳細ルールを使用してブラックリスト方式で設定することも可能。

設定


firewalldサービス設定


基本的にサービス設定を変更することはないが、サービスは下記に定義されている。
/usr/lib/systemd/system/firewalld.service

firewalld設定


firewalld自体の設定は次のパスのファイルで行われる。
/etc/firewalld/firewalld.conf


設定項目


DefaultZone


This sets the default zone for connections or interfaces if the
zone is not selected or specified by NetworkManager, initscripts or
command line tool. The default zone is public.

MinimalMark


For some firewall settings several rules are needed in different
tables to be able to handle packets in the correct way. To achieve
that these packets are marked using the MARK target iptables(8) and
ip6tables(8). With the MinimalMark option a block of marks can be
reserved for private use; only marks over this value are used. The
default MinimalMark value is 100.

CleanupOnExit


If firewalld stops, it cleans up all firewall rules. Setting this
option to no or false leaves the current firewall rules untouched.
The default value is yes or true.

Lockdown


If this option is enabled, firewall changes with the D-Bus
interface will be limited to applications that are listed in the
lockdown whitelist (see firewalld.lockdown-whitelist(5)). The
default value is no or false.

IPv6_rpfilter


If this option is enabled (it is by default), reverse path filter
test on a packet for IPv6 is performed. If a reply to the packet
would be sent via the same interface that the packet arrived on,
the packet will match and be accepted, otherwise dropped. For IPv4
the rp_filter is controlled using sysctl.

IndividualCalls


If this option is disabled (it is by default), combined -restore
calls are used and not individual calls to apply changes to the
firewall. The use of individiual calls increases the time that is
needed to apply changes and to start the daemon, but is good for
debugging as error messages are more specific.

LogDenied


Add logging rules right before reject and drop rules in the INPUT,
FORWARD and OUTPUT chains for the default rules and also final
reject and drop rules in zones for the configured link-layer packet
type. The possible values are: all, unicast, broadcast, multicast
and off. The default setting is off, which disables the logging.

AutomaticHelpers


FORWARD and OUTPUT chains for the default rules and also final
reject and drop rules in zones for the configured link-layer packet
type. The possible values are: all, unicast, broadcast, multicast
and off. The default setting is off, which disables the logging.

AutomaticHelpers


For the secure use of iptables and connection tracking helpers it
is recommended to turn AutomaticHelpers off. But this might have
side effects on other services using the netfilter helpers as the
sysctl setting in /proc/sys/net/netfilter/nf_conntrack_helper will
be changed. With the system setting, the default value set in the
kernel or with sysctl will be used. Possible values are: yes, no
and system. The default setting is system.

firewalld起動時オプション


firewalld起動時のオプションを設定できる。
ただし、現状使用できるオプションはデバッグオプションのみである。
/etc/sysconfig/firewalld


設定項目


debug


Set the debug level for firewalld to level. The range of the debug
level is 1 (lowest level) to 10 (highest level). The debug output
will be written to the firewalld log file /var/log/firewalld.



コマンド


firewall-cmd


firewalldの操作は基本的にfirewall-cmdコマンドを使用する

firewall-cmdヘルプ


[root@localhost ~]# firewall-cmd -h

Usage: firewall-cmd [OPTIONS...]

General Options
  -h, --help           Prints a short help text and exists
  -V, --version        Print the version string of firewalld
  -q, --quiet          Do not print status messages

Status Options
  --state              Return and print firewalld state
  --reload             Reload firewall and keep state information
  --complete-reload    Reload firewall and lose state information
  --runtime-to-permanent
                       Create permanent from runtime configuration

Log Denied Options
  --get-log-denied     Print the log denied value
  --set-log-denied=<value>
                       Set log denied value
  --get-ipset-types    Print the supported ipset types

Permanent Options
  --permanent          Set an option permanently
                       Usable for options marked with [P]

Zone Options
  --get-default-zone   Print default zone for connections and interfaces
  --set-default-zone=<zone>
                       Set default zone
  --get-active-zones   Print currently active zones
  --get-zones          Print predefined zones [P]
  --get-services       Print predefined services [P]
  --get-icmptypes      Print predefined icmptypes [P]
  --get-zone-of-interface=<interface>
                       Print name of the zone the interface is bound to [P]
  --get-zone-of-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
                       Print name of the zone the source is bound to [P]
  --list-all-zones     List everything added for or enabled in all zones [P]
  --new-zone=<zone>    Add a new zone [P only]
  --new-zone-from-file=<filename> [--name=<zone>]
                       Add a new zone from file with optional name [P only]
  --delete-zone=<zone> Delete an existing zone [P only]
  --load-zone-defaults=<zone>
                       Load zone default settings [P only] [Z]
  --zone=<zone>        Use this zone to set or query options, else default zone
                       Usable for options marked with [Z]
  --get-target         Get the zone target [P only] [Z]
  --set-target=<target>
                       Set the zone target [P only] [Z]
  --info-zone=<zone>   Print information about a zone
  --path-zone=<zone>   Print file path of a zone [P only]

IPSet Options
  --get-ipset-types    Print the supported ipset types
  --new-ipset=<ipset> --type=<ipset type> [--option=<key>[=<value>]]..
                       Add a new ipset [P only]
  --new-ipset-from-file=<filename> [--name=<ipset>]
                       Add a new ipset from file with optional name [P only]
  --delete-ipset=<ipset>
                       Delete an existing ipset [P only]
  --load-ipset-defaults=<ipset>
                       Load ipset default settings [P only]
  --info-ipset=<ipset> Print information about an ipset
  --path-ipset=<ipset> Print file path of an ipset [P only]
  --get-ipsets         Print predefined ipsets
  --ipset=<ipset> --set-description=<description>
                       Set new description to ipset [P only]
  --ipset=<ipset> --get-description
                       Print description for ipset [P only]
  --ipset=<ipset> --set-short=<description>
                       Set new short description to ipset [P only]
  --ipset=<ipset> --get-short
                       Print short description for ipset [P only]
  --ipset=<ipset> --add-entry=<entry>
                       Add a new entry to an ipset [P]
  --ipset=<ipset> --remove-entry=<entry>
                       Remove an entry from an ipset [P]
  --ipset=<ipset> --query-entry=<entry>
                       Return whether ipset has an entry [P]
  --ipset=<ipset> --get-entries
                       List entries of an ipset [P]
  --ipset=<ipset> --add-entries-from-file=<entry>
                       Add a new entries to an ipset [P]
  --ipset=<ipset> --remove-entries-from-file=<entry>
                       Remove entries from an ipset [P]

IcmpType Options
  --new-icmptype=<icmptype>
                       Add a new icmptype [P only]
  --new-icmptype-from-file=<filename> [--name=<icmptype>]
                       Add a new icmptype from file with optional name [P only]
  --delete-icmptype=<icmptype>
                       Delete an existing icmptype [P only]
  --load-icmptype-defaults=<icmptype>
                       Load icmptype default settings [P only]
  --info-icmptype=<icmptype>
                       Print information about an icmptype
  --path-icmptype=<icmptype>
                       Print file path of an icmptype [P only]
  --icmptype=<icmptype> --set-description=<description>
                       Set new description to icmptype [P only]
  --icmptype=<icmptype> --get-description
                       Print description for icmptype [P only]
  --icmptype=<icmptype> --set-short=<description>
                       Set new short description to icmptype [P only]
  --icmptype=<icmptype> --get-short
                       Print short description for icmptype [P only]
  --icmptype=<icmptype> --add-destination=<ipv>
                       Enable destination for ipv in icmptype [P only]
  --icmptype=<icmptype> --remove-destination=<ipv>
                       Disable destination for ipv in icmptype [P only]
  --icmptype=<icmptype> --query-destination=<ipv>
                       Return whether destination ipv is enabled in icmptype [P only]
  --icmptype=<icmptype> --get-destinations
                       List destinations in icmptype [P only]

Service Options
  --new-service=<service>
                       Add a new service [P only]
  --new-service-from-file=<filename> [--name=<service>]
                       Add a new service from file with optional name [P only]
  --delete-service=<service>
                       Delete an existing service [P only]
  --load-service-defaults=<service>
                       Load icmptype default settings [P only]
  --info-service=<service>
                       Print information about a service
  --path-service=<service>
                       Print file path of a service [P only]
  --service=<service> --set-description=<description>
                       Set new description to service [P only]
  --service=<service> --get-description
                       Print description for service [P only]
  --service=<service> --set-short=<description>
                       Set new short description to service [P only]
  --service=<service> --get-short
                       Print short description for service [P only]
  --service=<service> --add-port=<portid>[-<portid>]/<protocol>
                       Add a new port to service [P only]
  --service=<service> --remove-port=<portid>[-<portid>]/<protocol>
                       Remove a port from service [P only]
  --service=<service> --query-port=<portid>[-<portid>]/<protocol>
                       Return whether the port has been added for service [P only]
  --service=<service> --get-ports
                       List ports of service [P only]
  --service=<service> --add-protocol=<protocol>
                       Add a new protocol to service [P only]
  --service=<service> --remove-protocol=<protocol>
                       Remove a protocol from service [P only]
  --service=<service> --query-protocol=<protocol>
                       Return whether the protocol has been added for service [P only]
  --service=<service> --get-protocols
                       List protocols of service [P only]
  --service=<service> --add-source-port=<portid>[-<portid>]/<protocol>
                       Add a new source port to service [P only]
  --service=<service> --remove-source-port=<portid>[-<portid>]/<protocol>
                       Remove a source port from service [P only]
  --service=<service> --query-source-port=<portid>[-<portid>]/<protocol>
                       Return whether the source port has been added for service [P only]
  --service=<service> --get-source-ports
                       List source ports of service [P only]
  --service=<service> --add-module=<module>
                       Add a new module to service [P only]
  --service=<service> --remove-module=<module>
                       Remove a module from service [P only]
  --service=<service> --query-module=<module>
                       Return whether the module has been added for service [P only]
  --service=<service> --get-modules
                       List modules of service [P only]
  --service=<service> --set-destination=<ipv>:<address>[/<mask>]
                       Set destination for ipv to address in service [P only]
  --service=<service> --remove-destination=<ipv>
                       Disable destination for ipv i service [P only]
  --service=<service> --query-destination=<ipv>:<address>[/<mask>]
                       Return whether destination ipv is set for service [P only]
  --service=<service> --get-destinations
                       List destinations in service [P only]

Options to Adapt and Query Zones
  --list-all           List everything added for or enabled in a zone [P] [Z]
  --list-services      List services added for a zone [P] [Z]
  --timeout=<timeval>  Enable an option for timeval time, where timeval is
                       a number followed by one of letters 's' or 'm' or 'h'
                       Usable for options marked with [T]
  --set-description=<description>
                       Set new description to zone [P only] [Z]
  --get-description    Print description for zone [P only] [Z]
  --set-short=<description>
                       Set new short description to zone [P only] [Z]
  --get-short          Print short description for zone [P only] [Z]
  --add-service=<service>
                       Add a service for a zone [P] [Z] [T]
  --remove-service=<service>
                       Remove a service from a zone [P] [Z]
  --query-service=<service>
                       Return whether service has been added for a zone [P] [Z]
  --list-ports         List ports added for a zone [P] [Z]
  --add-port=<portid>[-<portid>]/<protocol>
                       Add the port for a zone [P] [Z] [T]
  --remove-port=<portid>[-<portid>]/<protocol>
                       Remove the port from a zone [P] [Z]
  --query-port=<portid>[-<portid>]/<protocol>
                       Return whether the port has been added for zone [P] [Z]
  --list-protocols     List protocols added for a zone [P] [Z]
  --add-protocol=<protocol>
                       Add the protocol for a zone [P] [Z] [T]
  --remove-protocol=<protocol>
                       Remove the protocol from a zone [P] [Z]
  --query-protocol=<protocol>
                       Return whether the protocol has been added for zone [P] [Z]
  --list-source-ports  List source ports added for a zone [P] [Z]
  --add-source-port=<portid>[-<portid>]/<protocol>
                       Add the source port for a zone [P] [Z] [T]
  --remove-source-port=<portid>[-<portid>]/<protocol>
                       Remove the source port from a zone [P] [Z]
  --query-source-port=<portid>[-<portid>]/<protocol>
                       Return whether the source port has been added for zone [P] [Z]
  --list-icmp-blocks   List Internet ICMP type blocks added for a zone [P] [Z]
  --add-icmp-block=<icmptype>
                       Add an ICMP block for a zone [P] [Z] [T]
  --remove-icmp-block=<icmptype>
                       Remove the ICMP block from a zone [P] [Z]
  --query-icmp-block=<icmptype>
                       Return whether an ICMP block has been added for a zone
                       [P] [Z]
  --add-icmp-block-inversion
                       Enable inversion of icmp blocks for a zone [P] [Z]
  --remove-icmp-block-inversion
                       Disable inversion of icmp blocks for a zone [P] [Z]
  --query-icmp-block-inversion
                       Return whether inversion of icmp blocks has been enabled
                       for a zone [P] [Z]
  --list-forward-ports List IPv4 forward ports added for a zone [P] [Z]
  --add-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
                       Add the IPv4 forward port for a zone [P] [Z] [T]
  --remove-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
                       Remove the IPv4 forward port from a zone [P] [Z]
  --query-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
                       Return whether the IPv4 forward port has been added for
                       a zone [P] [Z]
  --add-masquerade     Enable IPv4 masquerade for a zone [P] [Z] [T]
  --remove-masquerade  Disable IPv4 masquerade for a zone [P] [Z]
  --query-masquerade   Return whether IPv4 masquerading has been enabled for a
                       zone [P] [Z]
  --list-rich-rules    List rich language rules added for a zone [P] [Z]
  --add-rich-rule=<rule>
                       Add rich language rule 'rule' for a zone [P] [Z] [T]
  --remove-rich-rule=<rule>
                       Remove rich language rule 'rule' from a zone [P] [Z]
  --query-rich-rule=<rule>
                       Return whether a rich language rule 'rule' has been
                       added for a zone [P] [Z]

Options to Handle Bindings of Interfaces
  --list-interfaces    List interfaces that are bound to a zone [P] [Z]
  --add-interface=<interface>
                       Bind the <interface> to a zone [P] [Z]
  --change-interface=<interface>
                       Change zone the <interface> is bound to [Z]
  --query-interface=<interface>
                       Query whether <interface> is bound to a zone [P] [Z]
  --remove-interface=<interface>
                       Remove binding of <interface> from a zone [P] [Z]

Options to Handle Bindings of Sources
  --list-sources       List sources that are bound to a zone [P] [Z]
  --add-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
                       Bind the source to a zone [P] [Z]
  --change-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
                       Change zone the source is bound to [Z]
  --query-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
                       Query whether the source is bound to a zone [P] [Z]
  --remove-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
                       Remove binding of the source from a zone [P] [Z]

Direct Options
  --direct             First option for all direct options
  --get-all-chains
                       Get all chains [P]
  --get-chains {ipv4|ipv6|eb} <table>
                       Get all chains added to the table [P]
  --add-chain {ipv4|ipv6|eb} <table> <chain>
                       Add a new chain to the table [P]
  --remove-chain {ipv4|ipv6|eb} <table> <chain>
                       Remove the chain from the table [P]
  --query-chain {ipv4|ipv6|eb} <table> <chain>
                       Return whether the chain has been added to the table [P]
  --get-all-rules
                       Get all rules [P]
  --get-rules {ipv4|ipv6|eb} <table> <chain>
                       Get all rules added to chain in table [P]
  --add-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
                       Add rule to chain in table [P]
  --remove-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
                       Remove rule with priority from chain in table [P]
  --remove-rules {ipv4|ipv6|eb} <table> <chain>
                       Remove rules from chain in table [P]
  --query-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
                       Return whether a rule with priority has been added to
                       chain in table [P]
  --passthrough {ipv4|ipv6|eb} <arg>...
                       Pass a command through (untracked by firewalld)
  --get-all-passthroughs
                       Get all tracked passthrough rules [P]
  --get-passthroughs {ipv4|ipv6|eb} <arg>...
                       Get tracked passthrough rules [P]
  --add-passthrough {ipv4|ipv6|eb} <arg>...
                       Add a new tracked passthrough rule [P]
  --remove-passthrough {ipv4|ipv6|eb} <arg>...
                       Remove a tracked passthrough rule [P]
  --query-passthrough {ipv4|ipv6|eb} <arg>...
                       Return whether the tracked passthrough rule has been
                       added [P]

Lockdown Options
  --lockdown-on        Enable lockdown.
  --lockdown-off       Disable lockdown.
  --query-lockdown     Query whether lockdown is enabled

Lockdown Whitelist Options
  --list-lockdown-whitelist-commands
                       List all command lines that are on the whitelist [P]
  --add-lockdown-whitelist-command=<command>
                       Add the command to the whitelist [P]
  --remove-lockdown-whitelist-command=<command>
                       Remove the command from the whitelist [P]
  --query-lockdown-whitelist-command=<command>
                       Query whether the command is on the whitelist [P]
  --list-lockdown-whitelist-contexts
                       List all contexts that are on the whitelist [P]
  --add-lockdown-whitelist-context=<context>
                       Add the context context to the whitelist [P]
  --remove-lockdown-whitelist-context=<context>
                       Remove the context from the whitelist [P]
  --query-lockdown-whitelist-context=<context>
                       Query whether the context is on the whitelist [P]
  --list-lockdown-whitelist-uids
                       List all user ids that are on the whitelist [P]
  --add-lockdown-whitelist-uid=<uid>
                       Add the user id uid to the whitelist [P]
  --remove-lockdown-whitelist-uid=<uid>
                       Remove the user id uid from the whitelist [P]
  --query-lockdown-whitelist-uid=<uid>
                       Query whether the user id uid is on the whitelist [P]
  --list-lockdown-whitelist-users
                       List all user names that are on the whitelist [P]
  --add-lockdown-whitelist-user=<user>
                       Add the user name user to the whitelist [P]
  --remove-lockdown-whitelist-user=<user>
                       Remove the user name user from the whitelist [P]
  --query-lockdown-whitelist-user=<user>
                       Query whether the user name user is on the whitelist [P]

Panic Options
  --panic-on           Enable panic mode
  --panic-off          Disable panic mode
  --query-panic        Query whether panic mode is enabled

設定の再読み込み


firewall-cmd --reload
※ただしアクセス拒否設定を入れても、現在接続中の通信は直ちに切断されない場合がある。次のコマンドの場合は直ちに切断される。
systemctl restart firewalld


ACL


ACLの設定は基本的にfirewall-cmdコマンドで行うが、内部的にはXMLで管理されている。

設定反映


設定反映を行うには、次のコマンドの実行が必要
firewall-cmd --reload
※ただしアクセス拒否設定を入れても、現在接続中の通信は直ちに切断されない場合がある。次のコマンドの場合は直ちに切断される。
systemctl restart firewalld

サービス


一覧表示


定義されているサービス一覧は次のコマンドで確認できる。
firewall-cmd --get-services
ただし、改行されておらず見にくいので次のとおり実行すると良い。
firewall-cmd --get-services | sed -e "s/ /\n/g"


定義内容確認





定義追加




定義除去




ポート定義追加




ポート定義除去




定義ファイル(XML)


次のパス配下に存在する。新規に作成したものもこのパスに保存される。
/lib/firewalld/services/


ipset



パラメータ


タイプ


ipsetデータベース内の保存形式。
基本的にハッシュテーブル形式であるが、どの項目をキーにするかを設定可能。
次のコマンドで使用可能なタイプを確認できる。
firewall-cmd --get-ipset-types | sed -e "s/ /\n/g"


一覧表示


firewall-cmd --permanent --get-ipsets
※デフォルトゾーンの場合、明示的に割り当てていなければインタフェースは表示されない。

定義内容確認


firewall-cmd --permanent --info-ipset=<ipset名>

定義追加


firewall-cmd --permanent --new-ipset=<ipset名> --type=hash:ip

定義除去


firewall-cmd --permanent --delete-ipset=<ipset名>

定義変更


typeの変更はできない

アドレス設定確認




アドレス設定追加


firewall-cmd --permanent --ipset=<ipset名> --add-entry=<アドレス>

アドレス設定除去


firewall-cmd --permanent --ipset=<ipset名> --remove-entry=<アドレス>
※設定除去すると、設定再読み込みをしなくても直ちに反映されるので注意すること

定義ファイル(XML)


新規に作成した設定は次のパス配下に存在する。デフォルトのipsetは存在しない。
/etc/firewalld/ipsets/


ゾーン



一覧表示


firewall-cmd --list-all


定義内容確認


firewall-cmd --info-zone=<ゾーン名>

定義ファイル(XML)


定義ファイルはゾーンごとに作成される。
基本のパスはこちらである。
/etc/firewalld/zones/



ゾーン名


一覧表示


定義されているゾーン一覧は次のコマンドで確認できる。
firewall-cmd --permanent --get-zones
ただし、改行されておらず見にくいので次のとおり実行すると良い。
firewall-cmd --permanent --get-zones | sed -e "s/ /\n/g"



また、現在使用中のゾーン一覧は次のコマンドで確認できる。
firewall-cmd --get-active-zones


定義追加


firewall-cmd --permanent --new-zone=<ゾーン名>

定義除去


firewall-cmd --permanent --delete-zone=<ゾーン名>

デフォルトゾーン


作成したゾーンはインタフェースに割り当てることで機能するが、明示的に割り当てない場合、デフォルトゾーンに暗黙的に割り当てられる。
現在のデフォルトゾーンを確認するコマンドは以下である。
firewall-cmd --get-default-zone
変更する場合は、次のコマンドである。
firewall-cmd --set-default-zone=<ゾーン名>

ターゲット


ターゲットとはポリシーに合致しなかった場合のデフォルトの動作のことである。
パケット許可・破棄が選択できる。

設定確認


firewall-cmd --permanent --zone=<ゾーン名> --get-target

設定変更


firewall-cmd --permanent --zone=<ゾーン名> --set-target=<ターゲット名>


インタフェース


各インタフェースは1つのゾーンにしか属すことはできない。

設定確認




設定追加


firewall-cmd --permanent --zone=<ゾーン名> --add-interface=<インタフェース名>

設定除去


firewall-cmd --permanent --zone=<ゾーン名> --remove-interface=<インタフェース名>

設定変更


インタフェースに割り当てたゾーンを変更する
firewall-cmd --permanent --zone=<ゾーン名> --change-interface=<インタフェース名>

送信元


ゾーン単位に定義するので、特定のサービスのみで定義する場合は、新規のゾーン作成が必要

一覧表示


firewall-cmd --permanent --zone=<ゾーン名> --list-sources

定義追加


firewall-cmd --permanent --zone=<ゾーン名> --add-source=<ネットワークアドレス>/<プレフィックス長>

定義除去


firewall-cmd --permanent --zone=<ゾーン名> --remove-source=<ネットワークアドレス>/<プレフィックス長>

サービス


一覧表示


firewall-cmd --permanent --zone=<ゾーン名> --list-services

定義追加


firewall-cmd --permanent --zone=<ゾーン名> --add-service=<サービス名>

定義除去


firewall-cmd --permanent --zone=<ゾーン名> --remove-service=<サービス名>

デスクリプション


ゾーンにはゾーンの内容を説明する記述を設定可能である。

設定確認


firewall-cmd --permanent --zone=<ゾーン名> --get-description

別名


設定確認


firewall-cmd --permanent --zone=<ゾーン名> --get-short

リッチルール



一覧表示


firewall-cmd --permanent --zone=<ゾーン名> --list-rich-rules

定義確認


firewall-cmd --permanent --zone=<ゾーン名> --query-rich-rule="<ルール内容>"

定義追加


firewall-cmd --permanent --zone=<ゾーン名> --add-rich-rule="<ルール内容>"

ルール内容書式

ルール内容は以下の書式で記述する。
ルール内でダブルクォーテーションを使用するが、add-rich-rule=”<ルール内容>”等の外側のダブルクォーテーションと自動で識別されるので、エスケープの必要はない。

基本書式

rule
	family="<IPバージョン>"
	source address="<送信元アドレス>"
	source-port port="<送信元ポート番号>" protocol="[tcp|udp]"
	destination address="<宛先アドレス>"
	service name="<サービス名>"
	[accept | reject | drop]

IPバージョン

省略できない。



送信元アドレス

省略した場合、全て許可される。


送信元ポート番号

省略した場合、全て許可される。
source-port port="<送信元ポート番号>" protocol="[tcp|udp]"

宛先アドレス

省略した場合、全て許可される。


宛先ポート番号

省略した場合、全て許可される。



アクション

[accept | reject | drop | mark]

ログ

log [prefix="prefix text"] [level="log level"] [limit value="rate/duration"]


ICMPタイプ

icmp-type name="<ICMPタイプ名>"


定義除去


firewall-cmd --permanent --zone=<ゾーン名> --remove-rich-rule="<ルール内容>"




Tips


HTTPの許可


  1. 現在ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=http
  2. 現在ルールが適用されていないことを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
  3. ルールを適用する
    firewall-cmd --add-service=http --zone=public --permanent
  4. ルールが適用されていることを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep http
  5. 設定を再読み込みして反映させる
    firewall-cmd --reload

TCP/8080(Tomcat)の許可


  1. 現在ルールが定義されていないか確認
    firewall-cmd --permanent --info-service=tomcat
  2. 新しいルールを定義
    firewall-cmd --new-service=tomcat --permanent
    firewall-cmd --service=tomcat --add-port=8080/tcp --permanent
  3. ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=tomcat
  4. 現在ルールが適用されていないことを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep tomcat
  5. ルールを適用する
    firewall-cmd --add-service=tomcat --zone=public --permanent
  6. ルールが適用されていることを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep tomcat
  7. 設定を再読み込みして反映させる
    firewall-cmd --reload

SSHを特定のIPアドレスからのみ許可


  1. 現在ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=ssh
  2. 現在ルールが適用されていることを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep ssh
  3. ルールを除去する
    firewall-cmd --permanent --zone=public --remove-service=ssh
  4. ルールが除去されていることを確認する
    firewall-cmd --list-services --zone=public --permanent | sed -e "s/ /\n/g" | grep ssh
  5. リッチルールが作成されていないことを確認する
    firewall-cmd --permanent --zone=public --list-rich-rules
  6. リッチルールを作成する
    firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="<IPアドレス>" service name="ssh" accept"
  7. リッチルールが作成されていることを確認する
    firewall-cmd --permanent --zone=public --list-rich-rules
  8. 設定を再読み込みして反映させる
    firewall-cmd --reload

ホワイトリスト方式に切り変える


※複数のNICがある場合、すべてのNICでほわりとリスト方式に切り替える

  1. 現在のデフォルトゾーンを確認
    firewall-cmd --get-default-zone
  2. デフォルトゾーンを変更する
    firewall-cmd --set-default-zone=trusted
  3. 現在のデフォルトゾーンがtrustedであることを確認
    firewall-cmd --get-default-zone
  4. 作成するipsetがないことを確認
    firewall-cmd --permanent --info-ipset=<ipset名>
  5. ipsetを作成する
    firewall-cmd --permanent --new-ipset=<ipset名> --type=hash:ip
  6. ipsetが作成されたことを確認
    firewall-cmd --permanent --info-ipset=<ipset名>
  7. ipsetにアドレスを登録する
    firewall-cmd --permanent --ipset=<ipset名> --add-entry=<IPアドレス>/32
  8. 登録したアドレスを確認する
    firewall-cmd --permanent --ipset=<ipset名> --get-entries
  9. リッチルールが作成されていないことを確認する
    firewall-cmd --permanent --zone=trusted --list-rich-rules
  10. リッチルールを作成する
    firewall-cmd --permanent --zone=trusted --add-rich-rule="rule source ipset=blacklist drop"
  11. リッチルールが作成されていることを確認する
    firewall-cmd --permanent --zone=trusted --list-rich-rules
  12. 設定を再読み込みして反映させる
    firewall-cmd --reload

SSHのポート番号を変更する


SSHのポート番号がデフォルトの場合、不正アクセスを受けやすい。
その為、インターネットに接続しているサーバではSSHのポート番号をポートスキャンを受けにくいハイポートに変更するとよい。
下記では10022番に変更している。

  1. 現在ルールが定義されていないか確認
    firewall-cmd --permanent --info-service=ssh_10022
  2. 新しいルールを定義
    firewall-cmd --permanent --new-service=ssh_10022
    firewall-cmd --permanent --service=ssh_10022 --add-port=10022/tcp
  3. ルールが定義されていることを確認
    firewall-cmd --permanent --info-service=ssh_10022
  4. 現在ルールが適用されていないことを確認する
    firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep ssh_10022
  5. ルールを適用する
    firewall-cmd --permanent --add-service=ssh_10022 --zone=public
  6. ルールが適用されていることを確認する
    firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep ssh_10022
  7. 設定を再読み込みして反映させる
    firewall-cmd --reload
  8. SSHサーバの設定を変更し、ポート番号を変える
    sed "s/^#Port 22/Port 10022/g" -i /etc/ssh/sshd_config
  9. SSHサーバの設定変更を有効にする
    systemctl restart sshd
  10. 作成したポートでSSH接続できることを確認する
    ssh localhost -p 10022
  11. デフォルトと作成した二つのSSHサービスがあることを確認する
    firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep ssh
  12. デフォルトのSSHサービスを削除する
    firewall-cmd --permanent --zone=public --remove-service=ssh
  13. SSHサービスのみがあることを確認する
    firewall-cmd --permanent --list-services --zone=public | sed -e "s/ /\n/g" | grep ssh
  14. 設定を再読み込みして反映させる
    firewall-cmd --reload
    ※直ちに現在のSSHコネクションが切断されるわけではない。
    ※Teratermマクロを使用している場合、サーバ名の後に”:10022″を付ける

Notice: Trying to get property 'queue' of non-object in /usr/local/wordpress/wp-includes/script-loader.php on line 2876

Warning: Invalid argument supplied for foreach() in /usr/local/wordpress/wp-includes/script-loader.php on line 2876