LoginSignup
0
0

More than 5 years have passed since last update.

最低限firewalldを操作するためのチートシート

Last updated at Posted at 2018-02-12

firewalld

概要

通信が入力される際、パケットフィルタを設定している入力にはゾーン(Zone)という単位があり、ゾーンはサービス(Service)という単位で構成され、サービスはポート番号と名前で定義されるXMLファイルで構成される。

firewalldを操作するには firewall-cmdというコマンドを使う。
--permanentオプションを付けると再起動後も保持される。付けないまま実行した場合、設定は揮発する(再起動後は消える。)。

動作を確認する

# firewall-cmd --state

echo
running

サービス定義ファイルを作る

/usr/lib/firewalld/services/*.xml が実体である。
パスはディストリビューションによって異なるかも知れない(CentOS7+, openSUSE Tumbleweedでは同じパスだった)

例:SSH

# cat /usr/lib/firewalld/services/ssh.xml
で、内容は

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>SSH</short>
  <description>Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful.</description>
  <port protocol="tcp" port="22"/>
</service>

のようになっている。このファイルに倣って書けば良い。ファイルのオーナーはroot:rootであり、パーミッションは644であるようだ。

サービス定義ファイルのリロードを行う

ファイルは追加しただけでは認識されない。
# firewall-cmd --reload

echo
success

サービスをゾーンに追加する

https(443/TCP)を通信許可するフィルタに追加する場合
# firewall-cmd --zone=public --permanent --add-service=https

echo
Success

ポート番号を追加する

TCPの2222ポートを通信許可するフィルタに追加したい
# firewall-cmd --zone=public --permanent --add-port=2222/tcp

echo
Success

その他

設定中のポート一覧

現在設定されているポート一覧
# firewall-cmd --zone=public --permanent --list-ports

echo
2222/tcp

設定中のサービス一覧

現在設定されているサービス一覧
# firewall-cmd --zone=public --permanent --list-services

echo
dhcpv6-client ssh ore-ssh

追加可能なサービス一覧

# firewall-cmd --get-services

echo
# firewall-cmd --get-services
RH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry docker-swarm dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target kadmin kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls managesieve mdns minidlna mosh mountd ms-wbt mssql murmur mysql nfs nfs3 nrpe ntp openvpn ore-ssh ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius redis rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server

Firewalldのフィルタ確認

iptablesへ設定が書き込まれるので、 iptables -Lなどして状態の確認を行う(が、見づらい)。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0