【firewalld】如何通过firewalld限制只有特定源ip才能放行访问?

只需要限制源ip,放行所有tcp udp 端口

cat set-firewalld.sh

#!/bin/bash

ips="
127.0.0.1
172.16.15.3
172.16.15.4
172.16.15.5
"

sudo systemctl start  firewalld
sudo systemctl enable firewalld

sudo firewall-cmd --permanent --zone=public --add-port=22/tcp

for ip in ${ips}
do
    sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address='"${ip}"' accept'
done

sudo firewall-cmd --reload

# firewall-cmd --list-all

public
  target: default
  icmp-block-inversion: no
  interfaces:
  sources:
  services: dhcpv6-client ssh
  ports: 22/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
        rule family="ipv4" source address="127.0.0.1" accept
        rule family="ipv4" source address="172.16.15.3" accept
        rule family="ipv4" source address="172.16.15.4" accept
        rule family="ipv4" source address="172.16.15.5" accept

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容