IP Centos 7 ファイアウォールへの SMTP サービスをブロックする

IP Centos 7 ファイアウォールへの SMTP サービスをブロックする

CentOS 7 ファイアウォールを備えたサーバーで SMTP サービスを使用するために IP をブロックする方法を知りたいです。次のようなものを使用しようとしています:

   firewall-cmd --permanent --zone="public" --add-rich-rule='rule family=ipv4 source address=[ipadress] --remove-service=smtp'

しかし、正しい構文ではありません

それとも、TCP ポート 25、465、587 をブロックする必要がありますか?

また、ファイルからIPアドレスを自動的に取得する方法を誰かが教えてくれたら(可能であれば)嬉しいです。

答え1

マニュアルページに記載されている正しい構文は次のfirewalld.richlanguage(5)とおりです。

# firewall-cmd --zone="FedoraWorkstation" \
  --add-rich-rule='rule family=ipv4 source address=1.2.3.4 service name=smtp reject'
success

# iptables-save | grep 1.2.3.4
-A IN_FedoraWorkstation_deny -s 1.2.3.4/32 -p tcp -m tcp --dport 25 -m conntrack --ctstate NEW -j REJECT --reject-with icmp-port-unreachable

これは、サービス ファイルに記述されているように、ポート 25/tcp への着信トラフィックに適用されることに注意してください/usr/lib/firewalld/services/smtp.xml

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Mail (SMTP)</short>
  <description>This option allows incoming SMTP mail delivery. If you need to allow remote hosts to connect directly to your machine to deliver mail, enable this option. You do not need to enable this if you collect your mail from your ISP's server by POP3 or IMAP, or if you use a tool such as fetchmail. Note that an improperly configured SMTP server can allow remote machines to use your server to send spam.</description>
  <port protocol="tcp" port="25"/>
</service>

関連情報