Skip to content

Instantly share code, notes, and snippets.

@buzztaiki
Last active January 9, 2026 15:46
Show Gist options
  • Select an option

  • Save buzztaiki/9c56388ca4742a30fac006f5f3e0e815 to your computer and use it in GitHub Desktop.

Select an option

Save buzztaiki/9c56388ca4742a30fac006f5f3e0e815 to your computer and use it in GitHub Desktop.
firewalld メモ

firewalld メモ

Laptop には何らかの firewall は入れたいけど、nft を直接使うのは面倒だし、ufw は iptables (iptables-nft にすればいいけど) ベースだしという事で、firewalld を軽く触ってみたメモ。

リンク

コマンド

  • firewalld firewall daemon。systemctl で起動する。
  • firewall-cmd CLI。
  • firewall-applet タスクトレイ。今どきなら自動起動してくれる。

手軽に使える程度に必要な概念

  • zone ごとにルールが決められる。
  • iface や portsetを zone と紐付けて、この iface はこの zone みたいにできる
  • default zone があって、紐付けがない場合はそれになる。
  • default zone がどこになるかは cli で動的に変更できる。
  • 残念ながら、wifi station ごとに zone を変える事はできない。network manager を使っている場合は少しましになるかもしれない。

かるく検証

起動すると default zone は pubilc になっている

❯❯ firewall-cmd --list-all
public (default, active)
  target: default
  ingress-priority: 0
  egress-priority: 0
  icmp-block-inversion: no
  interfaces:
  sources:
  services: dhcpv6-client ssh
  ports:
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

nft を確認すると table が登録されている

❯❯ sudo nft list tables
table inet firewalld

各 zone の設定はおおむねこんな感じ

❯❯ firewall-cmd --list-all-zones | grep -Ee '^[^ ]|target:|services:'
block
  target: %%REJECT%%
  services:
dmz
  target: default
  services: ssh
docker (active)
  target: ACCEPT
  services:
drop
  target: DROP
  services:
external
  target: default
  services: ssh
home
  target: default
  services: dhcpv6-client mdns samba-client ssh
internal
  target: default
  services: dhcpv6-client mdns samba-client ssh
public (default, active)
  target: default
  services: dhcpv6-client ssh
trusted
  target: ACCEPT
  services:
work
  target: default
  services: dhcpv6-client ssh

default zone を変更する

GUI のメニューから選んでやるのが楽。CLI の場合は以下:

❯❯ firewall-cmd --set-default-zone=work
success

Sheild Up

アプレットからボタン一つで制限の厳しい zone に変更できる。デフォルトは block zone。

Block all network traffic (Panic)

アプレットから Block all network traffic を選ぶと全てのトラフィックが遮断される。何故かアプレットも使えなくなる。 Block all network traffic は firewall-cmd --panic-on と同じ事をしている。

man page から引用:

--panic-on Enable panic mode. All incoming and outgoing packets are dropped, active connections will expire. Enable this only if there are serious problems with your network environment. For example if the machine is getting hacked in.

This is a runtime only change.

--panic-off Disable panic mode. After disabling panic mode established connections might work again, if panic mode was enabled for a short period of time.

This is a runtime only change.

--query-panic Returns 0 if panic mode is enabled, 1 otherwise.

panic-on だと、netfilter に firewalld_policy_drop table が追加される。

❯❯ sudo nft list tables
table inet firewalld
table inet firewalld_policy_drop

❯❯ sudo nft list table inet firewalld_policy_drop
table inet firewalld_policy_drop {
	chain raw_prerouting {
		type filter hook prerouting priority raw + 9; policy drop;
	}

	chain raw_output {
		type filter hook output priority raw + 9; policy drop;
	}
}

panic-off する事で元に戻る。

❯❯ firewall-cmd --panic-off
success

❯❯ sudo nft list tables
table inet firewalld
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment