差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
linux:commands:network:firewall-cmd [2022/09/13 08:36] – ともやん | linux:commands:network:firewall-cmd [2025/02/21 12:16] (現在) – [サービスで許可されるポートを調べる] ともやん | ||
---|---|---|---|
行 1: | 行 1: | ||
- | ====== firewalld(Fedora) ====== | + | ====== firewalld (Linux) ====== |
firewall-cmd は firewalld パッケージに含まれている。 | firewall-cmd は firewalld パッケージに含まれている。 | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo dnf install firewalld | + | <font color="# |
</ | </ | ||
</ | </ | ||
- | ===== 定義済みゾーンの確認 ===== | + | ===== 定義済みゾーンの確認 |
+ | Fedora 36\\ | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --get-zones | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 17: | 行 18: | ||
</ | </ | ||
- | ===== デフォルトゾーンの確認 ===== | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --get-default-zone | + | <font color="# |
+ | </ | ||
+ | <WRAP color_result_long>< | ||
+ | FedoraServer | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: cockpit dhcpv6-client ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | FedoraWorkstation (active) | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: wlp2s0 | ||
+ | sources: | ||
+ | services: dhcpv6-client mdns samba-client ssh vnc-server | ||
+ | ports: 1025-65535/ | ||
+ | protocols: | ||
+ | forward: no | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | block | ||
+ | target: %%REJECT%% | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | dmz | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | drop | ||
+ | target: DROP | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | external | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: yes | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | home | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: dhcpv6-client mdns samba-client ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | internal | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: dhcpv6-client mdns samba-client ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | libvirt | ||
+ | target: ACCEPT | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: dhcp dhcpv6 dns ssh tftp | ||
+ | ports: | ||
+ | protocols: icmp ipv6-icmp | ||
+ | forward: no | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | rule priority=" | ||
+ | |||
+ | nm-shared | ||
+ | target: ACCEPT | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: dhcp dns ssh | ||
+ | ports: | ||
+ | protocols: icmp ipv6-icmp | ||
+ | forward: no | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | rule priority=" | ||
+ | |||
+ | public | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: dhcpv6-client mdns ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | trusted | ||
+ | target: ACCEPT | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | work | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: dhcpv6-client mdns ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Ubuntu 22.04.1 LTS\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <font color="# | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | block dmz drop external home internal nm-shared public trusted work | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <font color="# | ||
+ | </ | ||
+ | <WRAP color_result_long>< | ||
+ | block | ||
+ | target: %%REJECT%% | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | dmz | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | drop | ||
+ | target: DROP | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | external | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: yes | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | home | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: dhcpv6-client mdns samba-client ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | internal | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: dhcpv6-client mdns samba-client ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | nm-shared | ||
+ | target: ACCEPT | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: dhcp dns ssh | ||
+ | ports: | ||
+ | protocols: icmp ipv6-icmp | ||
+ | forward: no | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | rule priority=" | ||
+ | |||
+ | public (active) | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: enp1s0 | ||
+ | sources: | ||
+ | services: dhcpv6-client ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | trusted | ||
+ | target: ACCEPT | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | work | ||
+ | target: default | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: | ||
+ | services: dhcpv6-client ssh | ||
+ | ports: | ||
+ | protocols: | ||
+ | forward: yes | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== デフォルトゾーンとアクティブゾーンの確認 ===== | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <font color="# | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | FedoraWorkstation | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <font color="# | ||
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
FedoraWorkstation | FedoraWorkstation | ||
+ | interfaces: wlp2s0 | ||
</ | </ | ||
</ | </ | ||
- | <WRAP left round tip 95%> | + | <WRAP left round tip 95% minfont_12> |
はじめに__デフォルトゾーンの確認を行っておくことは重要__です。\\ | はじめに__デフォルトゾーンの確認を行っておくことは重要__です。\\ | ||
< | < | ||
行 35: | 行 420: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --get-default-zone | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 41: | 行 426: | ||
</ | </ | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --list-services | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 47: | 行 432: | ||
</ | </ | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --zone=FedoraWorkstation --list-services | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 53: | 行 438: | ||
</ | </ | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --zone=FedoraServer --list-services | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 63: | 行 448: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --get-default-zone | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 69: | 行 454: | ||
</ | </ | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --get-active-zones | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 78: | 行 463: | ||
</ | </ | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --zone=FedoraServer --change-interface=enp8s0 | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 84: | 行 469: | ||
</ | </ | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --get-active-zones | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 94: | 行 479: | ||
</ | </ | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --list-services | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 114: | 行 499: | ||
</ | </ | ||
- | ===== デフォルトゾーンの変更 ===== | + | ===== デフォルトゾーンとアクティブゾーンの変更 ===== |
- | workゾーンへ変更 | + | デフォルトゾーンを FedoraServer |
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --set-default-zone=work | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
+ | success | ||
</ | </ | ||
- | </ | ||
- | |||
- | すべてのアクセスを許可するtrustedゾーンへ変更 | ||
- | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --set-default-zone=trusted | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
+ | FedoraServer | ||
</ | </ | ||
- | </ | ||
- | ※これらの変更はすぐに反映される。 | ||
- | |||
- | ===== アクティブゾーンの確認 ===== | ||
- | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --get-active-zones | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
- | FedoraServer | + | FedoraWorkstation |
- | interfaces: | + | interfaces: |
</ | </ | ||
</ | </ | ||
- | + | ※デフォルトゾーンを変更してもアクティブゾーンが変更される訳ではない🤔\\ | |
- | ===== アクティブゾーンの変更 | + | これらの変更はすぐに反映される🤔\\ |
+ | \\ | ||
+ | アクティブゾーンを FedoraServer へ変更\\ | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --zone=work --change-interface=ens33 | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
+ | success | ||
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <font color="# | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | FedoraServer | ||
+ | interfaces: wlp2s0 | ||
</ | </ | ||
</ | </ | ||
行 157: | 行 545: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --list-services | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 167: | 行 555: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --list-ports | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 177: | 行 565: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --get-services | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 187: | 行 575: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --permanent --add-service=ssh | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
+ | success | ||
</ | </ | ||
</ | </ | ||
行 196: | 行 585: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --permanent --remove-service=ssh | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
+ | success | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | 複数サービスの許可を一括で永続的に削除🤤\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <font color="# | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | success | ||
</ | </ | ||
</ | </ | ||
行 205: | 行 605: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --permanent --add-port=22022/ | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
+ | success | ||
</ | </ | ||
</ | </ | ||
行 214: | 行 615: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --permanent --remove-port=22022/ | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
+ | success | ||
</ | </ | ||
</ | </ | ||
行 223: | 行 625: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --permanent --add-source=192.168.1.0/ | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
+ | success | ||
</ | </ | ||
</ | </ | ||
行 233: | 行 636: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --permanent --add-source=192.168.1.0/ | + | <font color="# |
- | $ sudo firewall-cmd --permanent --add-source=192.168.1.1 --zone=drop | + | |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
+ | success | ||
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <font color="# | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | success | ||
</ | </ | ||
</ | </ | ||
行 243: | 行 652: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --list-sources --zone=drop | + | <font color="# |
192.168.1.0/ | 192.168.1.0/ | ||
</ | </ | ||
行 253: | 行 662: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --permanent --remove-source=192.168.1.0/ | + | <font color="# |
- | $ sudo firewall-cmd --permanent --remove-source=192.168.1.1 --zone=drop | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
行 263: | 行 672: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ sudo firewall-cmd --reload | + | <font color="# |
</ | </ | ||
<WRAP color_result>< | <WRAP color_result>< | ||
+ | success | ||
</ | </ | ||
</ | </ | ||
行 273: | 行 683: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ cat / | + | <font color="# |
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | <font color="# | ||
+ | <font color="# | ||
+ | <font color="# | ||
+ | <font color="# | ||
+ | <font color="# | ||
+ | <font color="# | ||
</ | </ | ||
- | <WRAP color_result> | ||
- | <code xml> | ||
- | <?xml version=" | ||
- | < | ||
- | < | ||
- | < | ||
- | <port protocol=" | ||
- | </ | ||
- | </ | ||
</ | </ | ||
行 289: | 行 698: | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
- | $ firewall-cmd --help | + | <font color="# |
</ | </ | ||
<WRAP color_result_long>< | <WRAP color_result_long>< |