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 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
RH-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>
  • linux/commands/network/firewall-cmd.1643481494.txt.gz
  • 最終更新: 2022/01/30 03:38
  • by ともやん