• centos防火墙根据系统大致有2种,一种是centos6时代的iptables;一种是centos7时代的firewalld;

  • CentOS 7中防火墙是一个非常的强大的功能,在CentOS 6.5中在iptables防火墙中进行了升级了

Centos7默认安装了firewalld,如果没有安装的话,则需要YUM命令安装;firewalld真的用不习惯,与之前的iptable防火墙区别太大。

安装Firewall命令:

yum install firewalld firewalld-config

Firewall开放常见端口:(80、443、21、22、53)

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

Firewall关闭常见端口:(80、443、21、22、53)

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

命令含义:

--zone #作用域

--add-port=80/tcp  #添加端口,格式为:端口/通讯协议

--permanent  #永久生效,没有此参数重启后失效

批量添加区间端口

firewall-cmd --zone=public --add-port=8000-9999/udp --permanent

firewall-cmd --zone=public --add-port=8000-9999/tcp --permanent

开启防火墙命令:

systemctl start firewalld.service

重启防火墙命令:

systemctl restart firewalld.service  或者   service firewalld restart  或者 firewall-cmd --reload

查看端口列表:

firewall-cmd --permanent --list-port

禁用防火墙

systemctl stop firewalld

设置开机启动

systemctl enable firewalld

停止并禁用开机启动

sytemctl disable firewalld

查看状态

systemctl status firewalld 或者 service firewalld status 或者 firewall-cmd --state

设置firewalld 允许指定IP访问某端口

1.防火墙规则

Postgresql端口设置。允许192.168.142.166访问5432端口

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="5432" accept"

redis端口设置。允许192.168.142.166访问6379端口

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="6379" accept"

2. 重启防火墙,使配置生效
systemctl restart firewalld.service

3. 查看配置结果,验证配置
firewall-cmd --list-all

4. 删除规则
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="11300" accept"
 
systemctl restart firewalld.service

5.规则查询端口是否打开
firewall-cmd --query-port=80/tcp

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

Centos7防火墙配置rich-rule实现IP端口限制访问 & firewall-cmd命令

rich-rule实现IP端口限制访问
1、添加规则
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.51.54.1" port protocol="tcp" port="80" accept"

2、批量添加网段
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.51.54.1/24" port protocol="tcp" port="80" accept"

3、暴露端口
#开启某个端口(所有IP可访问)
firewall-cmd --permanent --zone=public --add-port=80/tcp

4、删除策略:
firewall-cmd --permanent --zone=public --remove-port=80/tcp

5、批量添加屏蔽ip网段
firewall-cmd --permanent --zone="public" --add-rich-rule="rule family="ipv4" source address="10.30.125.0/24" drop"

#查看所有防火墙配置
firewall-cmd --list-all
#查看rich-rules
[root@new-center ~]# firewall-cmd --list-rich-rules
#重载firewalld
[root@new-center ~]# firewall-cmd --reload
success
#1、添加规则
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.168.1" port protocol="tcp" port="80" accept" #2、批量添加网段
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.51.54.1/24" port protocol="tcp" port="80" accept" #3、批量添加屏蔽ip网段
firewall-cmd --permanent --zone="public" --add-rich-rule="rule family="ipv4" source address="10.30.125.0/24" drop"
#
firewall-cmd --permanent --zone="public" --add-rich-rule="rule family="ipv4" source address="0.0.0.0/0" forward-port port="8000" protocol="tcp" to-port="8000" to-addr="192.168.11.118"" #4、删除rich rule
[root@new-center ~]# firewall-cmd --permanent --remove-rich-rule 'rule family="ipv4" source address="0.0.0.0/0" forward-port port="2224" protocol="tcp" to-port="2224" to-addr="192.168.11.241"'
success
[root@new-center ~]# firewall-cmd --list-rich-rules
rule family="ipv4" source address="0.0.0.0/0" forward-port port="8078" protocol="tcp" to-port="8080" to-addr="192.168.11.234"
rule family="ipv4" source address="0.0.0.0/0" forward-port port="8000" protocol="tcp" to-port="8000" to-addr="192.168.11.118"
rule family="ipv4" source address="0.0.0.0/0" forward-port port="3722" protocol="tcp" to-port="22" to-addr="192.168.11.249"

详解阅读:

CENTOS 7 FIREWALLD详解,添加删除策略

Centos7防火墙配置rich-rule实现IP端口限制访问 & firewall-cmd命令

Centos7——防火墙(Firewall)命令的更多相关文章

  1. CentOS7防火墙firewall

    一.Firewall 1. 从CentOS7开始,默认使用firewall来配置防火墙,没有安装iptables(旧版默认安装). 2. firewall的配置文件是以xml的格式,存储在 /usr/ ...

  2. CentOS7 防火墙Firewall常用命令

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld  停止: systemctl disab ...

  3. RHEL7 CentOS7 的 firewall命令简单介绍

    firewall 服务介绍 firewall 服务是 redhat7 和 centos7 系统默认安装好的防火墙服务,一个信任级别的概念来管理与之相关联的连接与接口.它支持 ipv4 与 ipv6,并 ...

  4. CentOS7防火墙firewall相关操作

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disabl ...

  5. Centos7防火墙常用命令及mask锁定不能添加端口问题

    一.开放端口 sudo firewall-cmd --zone=public --add-port=3000/tcp --permanent sudo firewall-cmd --reload 二. ...

  6. Centos7 防火墙常用命令 开启 关闭防火墙

    如果你的系统上没有安装使用命令安装 #yum install firewalld  //安装firewalld 防火墙 开启服务 # systemctl start firewalld.service ...

  7. centos7防火墙--firewall

    centos7的防火墙变成firewall了 systemctl start firewalld.service#启动firewallsystemctl stop firewalld.service# ...

  8. Centos7防火墙常用命令

    有些人安装的linux的系统默认防火墙不是iptables,而是firewall,那就得使用以下方式关闭防火墙了. >>>关闭防火墙 systemctl stop firewalld ...

  9. centos7 防火墙相关命令

    启动:systemctl start firewalld禁用:systemctl stop firewalld重新载入规则:firewall-cmd --reload查看所有打开的端口:firewal ...

  10. Centos7(Firewall)防火墙开启常见端口命令

    Centos7默认安装了firewalld,如果没有安装的话,则需要YUM命令安装:firewalld真的用不习惯,与之前的iptable防火墙区别太大,但毕竟是未来主流讲究慢慢磨合它的设置规则: 安 ...

随机推荐

  1. Solution Set -「ABC 193」

    「ABC 193A」Discount Link. 略. #include<cstdio> int main() { int a,b; scanf("%d %d",&am ...

  2. 解密TCP连接断开:四次挥手的奥秘和数据传输的安全

    TCP 连接断开 在当今数字化时代,互联网已经成为了人们生活中不可或缺的一部分.而在互联网的基础之上,TCP协议扮演着关键的角色,它负责着数据在网络中的可靠传输.在TCP连接的建立过程中,我们已经了解 ...

  3. C#软件架构设计原则

    软件架构设计原则 学习设计原则是学习设计模式的基础.在实际的开发过程中,并不是一定要求所有的代码都遵循设计原则,而是要综合考虑人力.成本.时间.质量,不刻意追求完美,要在适当的场景遵循设计原则.这体现 ...

  4. 从零用VitePress搭建博客教程(2) –VitePress默认首页和头部导航、左侧导航配置

    2. 从零用VitePress搭建博客教程(2) –VitePress默认首页和头部导航.左侧导航配置 接上一节: 从零用VitePress搭建博客教程(1) – VitePress的安装和运行 四. ...

  5. 用阿里云镜像Centos7通过rpm和源码编译方式安装MySQL5版本

    这里只说明安装和注意事项,更具体的配置如端口号.cnf文件配置等就不写了. 阿里云开源镜像站资源目录 (aliyun.com) 我用的是基础版本. 基础版本镜像是默认不联网的,可以用下面的命令ping ...

  6. ORB-SLAM3测试

    (一)环境搭建教程 1.Ubuntu18.04从零开始搭建orb slam3及数据集测试:https://blog.csdn.net/Skether/article/details/131320852 ...

  7. C# ConfigMan.cs

    public static class ConfigMan { public static string ReadKey(string key) { return ConfigurationManag ...

  8. c#中工厂模式详解

    总体介绍:   工厂模式主要有三种类型:简单工厂.工厂方法和抽象工厂,该模式用于封装和管理对象的创建,是一种创建型模式.   万物皆对象,创建对象时必然需要new该对象,当需要更改对象时,需要把项目中 ...

  9. sed 原地替换文件时遇到的趣事

    哈喽大家好,我是咸鱼 在文章<三剑客之 sed>中咸鱼向大家介绍了文本三剑客中的 sed sed 全名叫 stream editor,流编辑器,用程序的方式来编辑文本 那么今天咸鱼打算讲一 ...

  10. ST 表

    ST 表 定义 ST 表是用于解决 可重复贡献问题 的数据结构,通俗来说,一般可以解决区间查询问题. 区间最值和 \(gcd\) 我们以最大值为例,然后可以再推广到最小值和区间 \(gcd\) 首先你 ...