
CentOS Linux リリース 7.7.1908 (Core) を使用しています。
いくつかのポートを除くすべての TCP/UDP ポートからの着信および発信接続をブロックします。
OS の現在のファイアウォール構成は次のとおりです。
# firewall-cmd --get-active-zones
public
interfaces: ens160
# firewall-cmd --list-ports
5901/tcp 5902/tcp 5912/tcp 5911/tcp 5913/tcp 5914/tcp
# firewall-cmd --list-services
dhcpv6-client ssh
ファイアウォールは上記のポート経由の接続のみを許可しているようですが、22 (SSH)、80 (HTTP) などの特定のポートも使用できます。
これをどうすれば修正できますか?
答え1
iptablesで答えが見つかります
https://superuser.com/questions/769814/how-to-block-all-ports-except-80-443-with-iptables/770191
80と443の代わりに、必要なポートをそこに開くだけで済みます。
答え2
/etc/firewalld/zonesディレクトリを確認し、public.xmlを変更します。
デフォルトの /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="ssh"/>
<service name="dhcpv6-client"/>
<service name="cockpit"/>
</zone>
それから
firewall-cmd --reload
ゾーンをパブリックからドロップに変更できます。
cp /usr/lib/firewalld/zones/drop.xml /etc/firewalld/zones/
#Add to /etc/firewalld/zones/ the following to permit ssh.
<service name="ssh"/>
firewall-cmd --set-default-zone=drop
firewall-cmd --reload
デフォルトのファイアウォール ゾーンを DROP に変更することを選択した場合は、ポートを再度追加する必要がある場合があります。
firewall-cmd --permanent --add-port={5901,5902,5912.5911,5913,59124}/tcp
firewall-cmd --reload