ファイアウォールでIPアドレスを制限(CentOS8)

CentOS8の場合は、hosts.denyとhosts.allowの代わりにファイアウォールでIPアドレスの制限をする

firewall-cmd --list-all
実行結果
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: cockpit ftp http https ssh
  ports: 11000-11009/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
vi /etc/firewalld/zones/public.xml
public.xml抜粋
  <service name="ftp"/>

上記の部分を下記のように書き換える

public.xml抜粋
  <rule family="ipv4">
    <source address="xx.xx.xx.xx/32"/>
    <service name="ftp"/>
    <accept/>
  </rule>

xx.xx.xx.xxの部分には実際には数値を入れて、アクセス元となるPCのIPアドレスを指定する

編集後のpublic.xmlは以下のようになる

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="cockpit"/>
  <service name="http"/>
  <service name="https"/>
  <port port="11000-11009" protocol="tcp"/>
 
  <rule family="ipv4">
    <source address="xx.xx.xx.xx/32"/>
    <service name="ftp"/>
    <accept/>
  </rule>
</zone>
firewall-cmd --reload
firewall-cmd --list-all
実行結果
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: cockpit http https ssh
  ports: 11000-11009/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
        rule family="ipv4" source address="xx.xx.xx.xx/32" service name="ftp" accept

servicesからftpがなくなり
rich rules
rule family=“ipv4” source address=“xx.xx.xx.xx/32” service name=“ftp” accept
が追加された

  • ftpを全許可

という設定から

  • 特定のIPアドレスからのみftpを許可

という設定に変わった

  • 最終更新: 2023/05/18 11:35