跟表哥学运维之玩转Firewalld

admin 2023年3月8日09:19:56评论37 views字数 1838阅读6分7秒阅读模式

众所周知,在centos7以上的版本中,firewalld防火墙取代了iptables防火墙。相较于iptables防火墙而言,firewalld支持动态更新技术并加入了区域(zone)的概念。本文一起来看看firewalld防火墙的使用吧!

🌧️基本命令

#启动
systemctl start firewalld
#关闭
systemctl stop firewalld
#查看状态
systemctl status firewalld
#开机禁用
systemctl disable firewalld
#开机启用
systemctl enable firewalld

❄️常用命令

查看版本:

firewall-cmd --version

查看帮助:

firewall-cmd --help

显示状态:

firewall-cmd --state

查看所有打开的端口:

firewall-cmd --zone=public --list-ports

更新防火墙规则:

firewall-cmd --reload

添加端口:

firewall-cmd --zone=public --add-port=80/tcp --permanent

重新载入:

firewall-cmd --reload

删除:

firewall-cmd --zone= public --remove-port=80/tcp --permanent

🪐端口转发

添加(例如3306 -> 3336):

firewall-cmd --permanent --zone=public --add-forward-port=port=3336:proto=tcp:toport=3306:toaddr=

删除:

firewall-cmd --permanent --remove-forward-port=port=3306:proto=tcp:toport=3336:toaddr=

查看转发的端口:

firewall-cmd --list-forward-ports

查看当前开了哪些端口

其实一个服务对应一个端口,每个服务对应/usr/lib/firewalld/services下面一个xml文件。

firewall-cmd --list-services

查看还有哪些服务可以打开

firewall-cmd --get-services

查看所有打开的端口:

firewall-cmd --zone=public --list-ports

😵‍💫更新防火墙规则

#添加多个端口
firewall-cmd --permanent --zone=public --add-port=8080-8083/tcp
#删除某个端口
firewall-cmd --permanent --zone=public --remove-port=81/tcp
#针对某个 IP开放端口
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="6379" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.233" accept"
#删除某个IP
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.1.51" accept"
#针对一个ip段访问
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" accept"

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="9200" accept"
#添加操作后别忘了执行重载
firewall-cmd --reload

更多教程 关注我们

原文始发于微信公众号(kali黑客笔记):跟表哥学运维之玩转Firewalld

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年3月8日09:19:56
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   跟表哥学运维之玩转Firewalldhttps://cn-sec.com/archives/1247342.html

发表评论

匿名网友 填写信息