linux:commands:network:firewall-cmd

文書の過去の版を表示しています。


firewalld(Fedora)

firewall-cmd は firewalld パッケージに含まれている。

$ sudo dnf install firewalld

$ firewall-cmd --get-zones

FedoraServer FedoraWorkstation block dmz drop external home internal libvirt nm-shared public trusted work

$ firewall-cmd --get-default-zone

FedoraWorkstation

はじめにデフォルトゾーンの確認を行っておくことは重要です。
firewall-cmd コマンドを --zone オプションを省略して実行すると、すべての操作はデフォルトゾーンに対して行われます。
--zone オプションを省略して作業の手間を少なくするには、以降の手順のようにデフォルトゾーンの変更アクティブゾーンの変更をセットで行うことをオススメします。

--zone オプションを省略した場合の実行例:

$ firewall-cmd --get-default-zone

FedoraWorkstation

$ firewall-cmd --list-services

dhcpv6-client mdns samba-client ssh

$ firewall-cmd --zone=FedoraWorkstation --list-services

dhcpv6-client mdns samba-client ssh

$ firewall-cmd --zone=FedoraServer --list-services

cockpit dhcpv6-client ssh

例えば、デフォルトゾーンが FedoraWorkstation の状態でインタフェース enp8s0 のアクティブゾーンを FedoraWorkstation から FedoraServer へ変更した場合、--zone オプションを省略して操作を行うとアクティブゾーンに未使用な FedoraWorkstation を操作し続けることになるので、firewall-cmd コマンドはメッセージを表示するようになります。

$ firewall-cmd --get-default-zone

FedoraWorkstation

$ firewall-cmd --get-active-zones

FedoraWorkstation
  interfaces: enp8s0
libvirt
  interfaces: virbr0

$ sudo firewall-cmd --zone=FedoraServer --change-interface=enp8s0

success

$ firewall-cmd --get-active-zones

FedoraServer
  interfaces: enp8s0
libvirt
  interfaces: virbr0

$ firewall-cmd --list-services

You're performing an operation over default zone ('FedoraWorkstation'),
but your connections/interfaces are in zone 'FedoraServer,libvirt' (see --get-active-zones)
You most likely need to use --zone=FedoraServer option.

dhcpv6-client mdns samba-client ssh

メッセージ (翻訳):

デフォルトゾーン ('FedoraWorkstation') で操作を実行しています。
ただし、接続/インターフェースはゾーン 'FedoraServer,libvirt' にあります (--get-active-zones を参照)
ほとんどの場合、--zone=FedoraServer オプションを使用する必要があります。

workゾーンへ変更

$ sudo firewall-cmd --set-default-zone=work


すべてのアクセスを許可するtrustedゾーンへ変更

$ sudo firewall-cmd --set-default-zone=trusted


※これらの変更はすぐに反映される。

$ firewall-cmd --get-active-zones

FedoraServer
  interfaces: br0 ens33

$ sudo firewall-cmd --zone=work --change-interface=ens33


$ sudo firewall-cmd --list-services

dhcpv6-client mdns samba-client ssh

$ sudo firewall-cmd --list-ports

22022/tcp 3389/tcp 5901/tcp

$ firewall-cmd --get-services

H-Satellite-6 amanda-client amanda-k5-client amqp amqps apcupsd audit bacula bacula-client bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine cockpit condor-collector ctdb dhcp dhcpv6 dhcpv6-client distcc dns docker-registry docker-swarm dropbox-lansync elasticsearch etcd-client etcd-server finger freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target isns jenkins kadmin kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls lightning-network llmnr managesieve matrix mdns minidlna mongodb mosh mountd mqtt mqtt-tls ms-wbt mssql murmur mysql nfs nfs3 nmea-0183 nrpe ntp nut openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole plex pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius redis rpc-bind rsh rsyncd rtsp salt-master samba samba-client samba-dc sane sip sips slp smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh steam-streaming svdrp svn syncthing syncthing-gui synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-http wbem-https wsman wsmans xdmcp xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server

$ sudo firewall-cmd --permanent --add-service=ssh


$ sudo firewall-cmd --permanent --remove-service=ssh


$ sudo firewall-cmd --permanent --add-port=22022/tcp


$ sudo firewall-cmd --permanent --remove-port=22022/tcp


$ sudo firewall-cmd --permanent --add-source=192.168.1.0/24


drop ゾーンにIPアドレスを登録する。

$ sudo firewall-cmd --permanent --add-source=192.168.1.0/24 --zone=drop
$ sudo firewall-cmd --permanent --add-source=192.168.1.1 --zone=drop


拒否リストの表示

$ sudo firewall-cmd --list-sources --zone=drop
192.168.1.0/24 192.168.1.1


拒否リストの削除

$ sudo firewall-cmd --permanent --remove-source=192.168.1.0/24 --zone=drop
$ sudo firewall-cmd --permanent --remove-source=192.168.1.1 --zone=drop


$ sudo firewall-cmd --reload


各サービスの定義ファイルを調べることにより許可されるポートがわかる。

$ cat /usr/lib/firewalld/services/ldap.xml

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>LDAP</short>
  <description>Lightweight Directory Access Protocol (LDAP) server</description>
  <port protocol="tcp" port="389"/>
</service>

$ firewall-cmd --help


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
  --check-config       Check permanent configuration for errors

Log Denied Options
  --get-log-denied     Print the log denied value
  --set-log-denied=
                       Set log denied value

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=
                       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=
                       Print name of the zone the interface is bound to [P]
  --get-zone-of-source=[/]||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=    Add a new zone [P only]
  --new-zone-from-file= [--name=]
                       Add a new zone from file with optional name [P only]
  --delete-zone= Delete an existing zone [P only]
  --load-zone-defaults=
                       Load zone default settings [P only]
  --zone=        Use this zone to set or query options, else default zone
                       Usable for options marked with [Z]
  --info-zone=   Print information about a zone
  --path-zone=   Print file path of a zone [P only]

Policy Options
  --get-policies       Print predefined policies
  --get-active-policies 
                       Print currently active policies
  --list-all-policies  List everything added for or enabled in all policies
  --new-policy= 
                       Add a new empty policy
  --new-policy-from-file= [--name=]
                       Add a new policy from file with optional name override [P only]
  --delete-policy=
                       Delete an existing policy
  --load-policy-defaults=
                       Load policy default settings
  --policy=    Use this policy to set or query options
                       Usable for options marked with [O]
  --info-policy=
                       Print information about a policy
  --path-policy=
                       Print file path of a policy

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

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

Service Options
  --new-service=
                       Add a new service [P only]
  --new-service-from-file= [--name=]
                       Add a new service from file with optional name [P only]
  --delete-service=
                       Delete an existing service [P only]
  --load-service-defaults=
                       Load icmptype default settings [P only]
  --info-service=
                       Print information about a service
  --path-service=
                       Print file path of a service [P only]
  --service= --set-description=
                       Set new description to service [P only]
  --service= --get-description
                       Print description for service [P only]
  --service= --set-short=
                       Set new short description to service [P only]
  --service= --get-short
                       Print short description for service [P only]
  --service= --add-port=[-]/
                       Add a new port to service [P only]
  --service= --remove-port=[-]/
                       Remove a port from service [P only]
  --service= --query-port=[-]/
                       Return whether the port has been added for service [P only]
  --service= --get-ports
                       List ports of service [P only]
  --service= --add-protocol=
                       Add a new protocol to service [P only]
  --service= --remove-protocol=
                       Remove a protocol from service [P only]
  --service= --query-protocol=
                       Return whether the protocol has been added for service [P only]
  --service= --get-protocols
                       List protocols of service [P only]
  --service= --add-source-port=[-]/
                       Add a new source port to service [P only]
  --service= --remove-source-port=[-]/
                       Remove a source port from service [P only]
  --service= --query-source-port=[-]/
                       Return whether the source port has been added for service [P only]
  --service= --get-source-ports
                       List source ports of service [P only]
  --service= --add-helper=
                       Add a new helper to service [P only]
  --service= --remove-helper=
                       Remove a helper from service [P only]
  --service= --query-helper=
                       Return whether the helper has been added for service [P only]
  --service= --get-service-helpers
                       List helpers of service [P only]
  --service= --set-destination=:
[/] Set destination for ipv to address in service [P only] --service= --remove-destination= Disable destination for ipv i service [P only] --service= --query-destination=:
[/] Return whether destination ipv is set for service [P only] --service= --get-destinations List destinations in service [P only] --service= --add-include= Add a new include to service [P only] --service= --remove-include= Remove a include from service [P only] --service= --query-include= Return whether the include has been added for service [P only] --service= --get-includes List includes of service [P only] Options to Adapt and Query Zones and Policies --list-all List everything added for or enabled [P] [Z] [O] --timeout= 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= Set new description [P only] [Z] [O] --get-description Print description [P only] [Z] [O] --get-target Get the target [P only] [Z] [O] --set-target= Set the target [P only] [Z] [O] --set-short= Set new short description [Z] [O] --get-short Print short description [P only] [Z] [O] --list-services List services added [P] [Z] --add-service= Add a service [P] [Z] [O] [T] --remove-service= Remove a service [P] [Z] [O] --query-service= Return whether service has been added [P] [Z] [O] --list-ports List ports added [P] [Z] [O] --add-port=[-]/ Add the port [P] [Z] [O] [T] --remove-port=[-]/ Remove the port [P] [Z] [O] --query-port=[-]/ Return whether the port has been added [P] [Z] [O] --list-protocols List protocols added [P] [Z] [O] --add-protocol= Add the protocol [P] [Z] [O] [T] --remove-protocol= Remove the protocol [P] [Z] [O] --query-protocol= Return whether the protocol has been added [P] [Z] [O] --list-source-ports List source ports added [P] [Z] [O] --add-source-port=[-]/ Add the source port [P] [Z] [O] [T] --remove-source-port=[-]/ Remove the source port [P] [Z] [O] --query-source-port=[-]/ Return whether the source port has been added [P] [Z] [O] --list-icmp-blocks List Internet ICMP type blocks added [P] [Z] [O] --add-icmp-block= Add an ICMP block [P] [Z] [O] [T] --remove-icmp-block= Remove the ICMP block [P] [Z] [O] --query-icmp-block= Return whether an ICMP block has been added [P] [Z] [O] --list-forward-ports List IPv4 forward ports added [P] [Z] [O] --add-forward-port=port=[-]:proto=[:toport=[-]][:toaddr=
[/]] Add the IPv4 forward port [P] [Z] [O] [T] --remove-forward-port=port=[-]:proto=[:toport=[-]][:toaddr=
[/]] Remove the IPv4 forward port [P] [Z] [O] --query-forward-port=port=[-]:proto=[:toport=[-]][:toaddr=
[/]] Return whether the IPv4 forward port has been added [P] [Z] [O] --add-masquerade Enable IPv4 masquerade [P] [Z] [O] [T] --remove-masquerade Disable IPv4 masquerade [P] [Z] [O] --query-masquerade Return whether IPv4 masquerading has been enabled [P] [Z] [O] --list-rich-rules List rich language rules added [P] [Z] [O] --add-rich-rule= Add rich language rule 'rule' [P] [Z] [O] [T] --remove-rich-rule= Remove rich language rule 'rule' [P] [Z] [O] --query-rich-rule= Return whether a rich language rule 'rule' has been added [P] [Z] [O] Options to Adapt and Query Zones --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] --add-forward Enable forwarding of packets between interfaces and sources in a zone [P] [Z] [T] --remove-forward Disable forwarding of packets between interfaces and sources in a zone [P] [Z] --query-forward Return whether forwarding of packets between interfaces and sources has been enabled for a zone [P] [Z] Options to Adapt and Query Policies --get-priority Get the priority [P only] [O] --set-priority= Set the priority [P only] [O] --list-ingress-zones List ingress zones that are bound to a policy [P] [O] --add-ingress-zone= Add the ingress zone to a policy [P] [O] --remove-ingress-zone= Remove the ingress zone from a policy [P] [O] --query-ingress-zone= Query whether the ingress zone has been adedd to a policy [P] [O] --list-egress-zones List egress zones that are bound to a policy [P] [O] --add-egress-zone= Add the egress zone to a policy [P] [O] --remove-egress-zone= Remove the egress zone from a policy [P] [O] --query-egress-zone= Query whether the egress zone has been adedd to a policy [P] [O] Options to Handle Bindings of Interfaces --list-interfaces List interfaces that are bound to a zone [P] [Z] --add-interface= Bind the to a zone [P] [Z] --change-interface= Change zone the is bound to [P] [Z] --query-interface= Query whether is bound to a zone [P] [Z] --remove-interface= Remove binding of 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=[/]||ipset: Bind the source to a zone [P] [Z] --change-source=[/]||ipset: Change zone the source is bound to [Z] --query-source=[/]||ipset: Query whether the source is bound to a zone [P] [Z] --remove-source=[/]||ipset: Remove binding of the source from a zone [P] [Z] Helper Options --new-helper= --module= [--family=] Add a new helper [P only] --new-helper-from-file= [--name=] Add a new helper from file with optional name [P only] --delete-helper= Delete an existing helper [P only] --load-helper-defaults= Load helper default settings [P only] --info-helper= Print information about an helper --path-helper= Print file path of an helper [P only] --get-helpers Print predefined helpers --helper= --set-description= Set new description to helper [P only] --helper= --get-description Print description for helper [P only] --helper= --set-short= Set new short description to helper [P only] --helper= --get-short Print short description for helper [P only] --helper= --add-port=[-]/ Add a new port to helper [P only] --helper= --remove-port=[-]/ Remove a port from helper [P only] --helper= --query-port=[-]/ Return whether the port has been added for helper [P only] --helper= --get-ports List ports of helper [P only] --helper= --set-module= Set module to helper [P only] --helper= --get-module Get module from helper [P only] --helper= --set-family={ipv4|ipv6|} Set family for helper [P only] --helper= --get-family Get module from helper [P only] Direct Options --direct First option for all direct options --get-all-chains Get all chains [P] --get-chains {ipv4|ipv6|eb} Get all chains added to the table [P] --add-chain {ipv4|ipv6|eb}
Add a new chain to the table [P] --remove-chain {ipv4|ipv6|eb}
Remove the chain from the table [P] --query-chain {ipv4|ipv6|eb}
Return whether the chain has been added to the table [P] --get-all-rules Get all rules [P] --get-rules {ipv4|ipv6|eb}
Get all rules added to chain in table [P] --add-rule {ipv4|ipv6|eb}
... Add rule to chain in table [P] --remove-rule {ipv4|ipv6|eb}
... Remove rule with priority from chain in table [P] --remove-rules {ipv4|ipv6|eb}
Remove rules from chain in table [P] --query-rule {ipv4|ipv6|eb}
... Return whether a rule with priority has been added to chain in table [P] --passthrough {ipv4|ipv6|eb} ... Pass a command through (untracked by firewalld) --get-all-passthroughs Get all tracked passthrough rules [P] --get-passthroughs {ipv4|ipv6|eb} ... Get tracked passthrough rules [P] --add-passthrough {ipv4|ipv6|eb} ... Add a new tracked passthrough rule [P] --remove-passthrough {ipv4|ipv6|eb} ... Remove a tracked passthrough rule [P] --query-passthrough {ipv4|ipv6|eb} ... 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= Add the command to the whitelist [P] --remove-lockdown-whitelist-command= Remove the command from the whitelist [P] --query-lockdown-whitelist-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= Add the context context to the whitelist [P] --remove-lockdown-whitelist-context= Remove the context from the whitelist [P] --query-lockdown-whitelist-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= Add the user id uid to the whitelist [P] --remove-lockdown-whitelist-uid= Remove the user id uid from the whitelist [P] --query-lockdown-whitelist-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= Add the user name user to the whitelist [P] --remove-lockdown-whitelist-user= Remove the user name user from the whitelist [P] --query-lockdown-whitelist-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

  • linux/commands/network/firewall-cmd.1663025576.txt.gz
  • 最終更新: 2022/09/13 08:32
  • by ともやん
Fedora 版の UBI Micro を独自に作る方法 (非公式😅)2024/05/02 13:38[参考文献]
Rust 関連2024/05/02 12:11[Fedora (Rust 公式から...)]
ESP32 Rust 開発環境のインストール2024/05/02 12:09[プロジェクトテンプレートの使用]
ImHex - リバースエンジニアのためのバイナリエディタ2024/05/01 09:54[ImHex - リバースエンジニアのためのバイナリエディタ]
JupyterLab + Rust 開発環境の構築2024/04/30 07:06[DietPi でビルドがエラー終了する]
Fedora Remix アップグレード (31 → 32)2024/04/29 21:22[システムのアップグレード]
Fedora NVIDIA ドライバ インストール ガイド2024/04/28 01:49[エラー: implicit declaration of function ‘acpi_bus_get_device’; did you mean ‘acpi_is_pnp_device’?]
Linux 関連2024/04/28 01:42↷ 移動操作に合わせてリンクを書き換えました。
Fedora に NVIDIA CUDA をインストールする方法2024/04/28 01:42↷ linux:fedora:install_nvidia_cuda から linux:fedora:rpmfusion_install_nvidia_cuda へページを名称変更しました。
Jupyter AI - JupyterLab の生成 AI 拡張機能2024/04/27 04:13[pipx]
Raspberry Pi Zero WH VideoCore IV GPU で OpenCL🤤2024/04/26 07:30[clinfo で動作確認😍]