firewalld

ファイアウォール動作状況確認

# systemctl status firewalld

ファイアウォール再起動

# systemctl restart firewalld

デフォルトゾーン確認

# firewall-cmd --list-all

定義されているサービス一覧の表示

# firewall-cmd --get-services

デフォルトゾーンで許可されているサービスの確認

  • 出力は一例
    # firewall-cmd --list-service
    dns http https mdns mysql-vpn openvpn pop3s samba-vpn smtp smtp-submission smtps ssh-port

既存サービスの有効化(http)

firewalld を再起動/設定反映するまで反映されない。

# firewall-cmd --permanent --add-service=http

ユーザ定義サービスの追加(sshd)

  • ポート変更。
  • 雛形を /usr/lib/firewalld/services から /etc/firewalld/services へコピーして編集する。
    # cp -a /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/ssh-port.xml
  • /etc/firewalld/services/ssh-port.xml
    <?xml version="1.0" encoding="utf-8"?>
    <service>
      <short>SSH-Port</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="20022"/>
    </service>
  • 既存のサービスを削除、修正したサービスを追加、反映。
    # firewall-cmd --permanent --delete-service=ssh
    # firewall-cmd --permanent --add-service=ssh-port
    # firewall-cmd --reload

ユーザ定義サービスの追加(samba)

  • VPNクライアントからの接続のみを許可。OpenVPN#仮想NIC
  • 雛形を /usr/lib/firewalld/services から /etc/firewalld/services へコピーして編集する。
    # cp -a /usr/lib/firewalld/services/samba.xml /etc/firewalld/services/samba-vpn.xml
  • /etc/firewalld/services/samba-vpn.xml
    <?xml version="1.0" encoding="utf-8"?>
    <service>
      <short>Samba</short>
      <description>This option allows you to access and participate in Windows file and printer sharing networks. You need the samba package installed for this option to be useful.</description>
      <port protocol="tcp" port="445"/>
      <destination ipv4="192.168.1.0/24"/>
    </service>
  • 既存のサービスを削除、修正したサービスを追加、反映。
    # firewall-cmd --permanent --delete-service=samba
    # firewall-cmd --permanent --add-service=samba-vpn
    # firewall-cmd --reload

デフォルトゾーンで許可されているポートの確認

# firewall-cmd --list-port

ポートの追加

firewalld を再起動/設定反映するまで反映されない。

# firewall-cmd --permanent --add-port=30001/tcp

設定反映

# firewall-cmd --reload