首页 > 数据库 > 数据库开发技术 > 跟表哥学运维之玩转Firewalld
众所周知,在
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笔记;如有侵权,请联系管理员删除。