RHEL7、CentOS7防火墙管理

时间:2022-12-30 16:19:39

  经常start、stop、restart操作防火墙有两种方式:

1、service iptables stop

2、/etc/init.d/iptables stop

  但是经常会有这种错误,因为在RHEL7、CentOS种其实没有这个服务。

[root@rhel7 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)
[root@rhel7 ~]# service iptables stop
Redirecting to /bin/systemctl stop iptables.service
[root@rhel7 ~]# /etc/init.d/iptables stop
-bash: /etc/init.d/iptables: No such file or directory

  或者

[root@CTU1000094955 ~]#  cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@CTU1000094955 ~]# service iptables stop
Redirecting to /bin/systemctl stop iptables.service
Failed to stop iptables.service: Unit iptables.service not loaded.
[root@CTU1000094955 ~]# /etc/init.d/iptables stop
-bash: /etc/init.d/iptables: No such file or directory

  原来在RHEL7、CentOS7开始,使用systemctl工具来管理服务程序,包括了service和chkconfig。

[root@CTU1000094955 ~]# systemctl list-unit-files|grep firewall
firewalld.service disabled

  那么systemctl管理防火墙:

启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service;echo $?
查看已启动的服务列表:systemctl list-unit-files|grep enabled

示例:

1、关闭防火墙并查看运行状态

[root@CTU1000094955 ~]# systemctl stop firewalld.service
[root@CTU1000094955 ~]# systemctl list-unit-files |grep firewall
firewalld.service disabled
[root@CTU1000094955 ~]# firewall-cmd --permanent --list-port
FirewallD is not running
[root@CTU1000094955 ~]# systemctl status firewalld.service
?.firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead) Nov :: CTU1000094955 systemd[]: Starting firewalld - dynamic firewall daemon...
Nov :: CTU1000094955 systemd[]: Started firewalld - dynamic firewall daemon.
Nov :: CTU1000094955 systemd[]: Started firewalld - dynamic firewall daemon.
Nov :: CTU1000094955 systemd[]: Stopping firewalld - dynamic firewall daemon...
Nov :: CTU1000094955 systemd[]: Stopped firewalld - dynamic firewall daemon.

2、开启防火墙并查看防护墙状态

[root@CTU1000094955 ~]# systemctl start firewalld.service
[root@CTU1000094955 ~]# systemctl status firewalld.service
?.firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Sat -- :: CST; 5s ago
Main PID: (firewalld)
CGroup: /system.slice/firewalld.service
?.. /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid Nov :: CTU1000094955 systemd[]: Starting firewalld - dynamic firewall daemon...
Nov :: CTU1000094955 systemd[]: Started firewalld - dynamic firewall daemon.
[root@CTU1000094955 ~]# systemctl list-unit-files |grep firewall
firewalld.service disabled
[root@CTU1000094955 ~]# firewall-cmd --permanent --list-port
/tcp /tcp

  与此同时,还可以通过firewall -cmd来操作防火墙

[root@CTU1000094955 ~]# man firewall-cmd
FIREWALL-CMD() firewall-cmd FIREWALL-CMD() NAME
firewall-cmd - firewalld command line client SYNOPSIS
firewall-cmd [OPTIONS...] DESCRIPTION
firewall-cmd is the command line client of the firewalld daemon. It provides interface to manage runtime and permanent configuration. The runtime configuration in firewalld is separated from the permanent configuration. This means that things can get changed in the runtime or permanent configuration. OPTIONS
The following options are supported: General Options
-h, --help
Prints a short help text and exits. -V, --version
Print the version string of firewalld. This option is not combinable with other options. -q, --quiet
Do not print status messages. Status Options
--state
Check whether the firewalld daemon is active (i.e. running). Returns an exit code if it is active, NOT_RUNNING otherwise (see the section called ?.XIT CODES?.. This will
also print the state to STDOUT. --reload
Reload firewall rules and keep state information. Current permanent configuration will become new runtime configuration, i.e. all runtime only changes done until reload are
lost with reload if they have not been also in permanent configuration. --complete-reload

3、查看防火墙是否运行

[root@CTU1000094955 ~]# firewall-cmd --state
running

4、查看默认通过防火墙

[root@CTU1000094955 ~]# firewall-cmd --permanent --list-port
/tcp /tcp

  刚才测试添加了10001、80两个端口,参数--permanent 是永久配置机子重启依然有效。

5、删除默认通过防火墙的端口

[root@CTU1000094955 ~]# firewall-cmd --permanent --remove-port=/tcp
success
[root@CTU1000094955 ~]# firewall-cmd --permanent --list-port
/tcp

  可以看到刚刚能通过防火墙的80端口现在已经查不到了。

6、添加端口到防火墙例外

[root@CTU1000094955 ~]# firewall-cmd --permanent --zone=public --add-port=/tcp
success
[root@CTU1000094955 ~]# firewall-cmd --permanent --list-port
/tcp /tcp

  现在80端口又回来了。

RHEL7、CentOS7防火墙管理的更多相关文章

  1. 【RHEL7/CentOS7防火墙之firewall-cmd命令详解】

    目录 Firewalld zone firewall-cmd 开始配置防火墙策略 总结 Redhat Enterprise Linux7已默认使用firewalld防火墙,其管理工具是firewall ...

  2. centos7防火墙管理的变化

    当我们在centos7中输入service iptables status 查看系统的防火墙状态,会出现如下错误: 网上查阅才知道centos7的防火墙管理工具变了,原来的iptables已经不用了, ...

  3. CentOS7防火墙管理firewalld

    学习apache安装的时候需要打开80端口,由于centos 7版本以后默认使用firewalld后,网上关于iptables的设置方法已经不管用了,想着反正iptable也不太熟悉,索性直接搬官方文 ...

  4. Django Linux环境下部署CentOS7+Python3+Django+uWSGI+Nginx(含Nginx返回400问题处理、防火墙管理)

    本文将介绍如何在Linux系统上部署Django web项目,本次部署基于下面的架构: CentOS7+ Python3.5 + Django1.11 + uWSGI + Nginx 亲测可行!!按照 ...

  5. RHEL7 CentOS7 检查查看精简指令

    RHEL7 CentOS7 检查查看精简指令: //////////////////////////检查查看精简指令://///////////////////////////// ///////// ...

  6. Centos7防火墙快速开放端口配置方法

    ▲这篇文章主要为大家详细介绍了Centos7防火墙开放端口的快速方法,感兴趣的小伙伴们可以参考一下! Firewalld服务是红帽RHEL7系统中默认的防火墙管理工具,特点是拥有运行时配置与永久配置选 ...

  7. linux入门系列10--firewalld防火墙管理

    上一篇文章学习了用户及文件相关权限,本篇继续学习防火墙技术. 防火墙作为公网与内网之间的保护屏障,对系统至关重要.防火墙又分为硬件防火墙和软件防火墙,主要功能都是依据设置的策略对穿越防火墙的流量进行过 ...

  8. CentOS7 防火墙(firewall)的操作命令

    CentOS7 防火墙(firewall)的操作命令 安装:yum install firewalld 1.firewalld的基本使用 启动: systemctl start firewalld 查 ...

  9. CentOS7 防火墙配置firewall-cmd

    firewalld(Dynamic Firewall Manager of Linux systems,Linux系统的动态防火墙管理器)服务是默认的防火墙配置管理工具. firewall-cmd 是 ...

随机推荐

  1. IO流-----写到输出流

    输出流:---链接:http://blog.csdn.net/du_minchao/article/details/49045421 /** * 方法名:writeStream * 方法描述:写到输出 ...

  2. js 定时器的使用。 setInterval()

    我需要实现的功能是:点击发送按钮,会出现 “已发送60s后可点击重发”,并且,60s 这个数字是随时变化的,60,59,58,57....0,然后再次返回到 发送 按钮. 类似效果,可参考  360首 ...

  3. Ueditor防止代码自动清除

    Ueditor功能真的很牛逼,可也有让人悲催的地方,尤其是自动清除代码,会将你默认的div标签改成p,挺让人闹心的,不过Ueditor的开发人员还是满热心的,搜遍网上无答案的时候,问了下他们,解决了 ...

  4. jQuery Validate 插件[表单验证 属性介绍]

    详细介绍一下Validate插件 $("#form的Id").validate({ }) 属性 规则 描述 required:true 必须输入的字段 required: &quo ...

  5. IE10用video标签播放本地mp4文件失败的解决办法

    1. 首先用“格式工厂”将要播放的视频文件按照“AVC高质量与大小”转换为要求格式的mp4文件: 2. 设置IIS7.5,添加mp4的MIME类型,步骤如下: 1.打开IIS管理器(运行inetmgr ...

  6. HTML5小游戏UI美化版

    HTML5小游戏[是男人就下一百层]UI美化版 之前写的小游戏,要么就比较简单,要么就是比较难看,或者人物本身是不会动的. 结合了其它人的经验,研究了一下精灵运动,就写一个简单的小游戏来试一下. 介绍 ...

  7. php基础知识(二)---2017-04-14

    1.字符串的三种表达形式: (1)双引号 (2)单引号 (3)尖括号 $s = <<<A <div style="width:500px; height:100px; ...

  8. webstorm中github的配置

    1.申请一个github账号,我这里的操作是已经有了账号的情况之下进行的. 打开webstorm,File-->settings,弹出settings框,输入git,得到以下界面,输入githu ...

  9. 妙用 scale 与 transfrom-origin,精准控制动画方向

    上次发完 不可思议的纯 CSS 导航栏下划线跟随效果 这篇文章之后,很多朋友找我讨论,感叹 CSS 的奇妙. 然后昨天,群里一位朋友问到了一个和这个效果比较类似的效果,问如何 将下面这个动画的下划线效 ...

  10. java日志系统中的 NDC

    NDC https://www.cnblogs.com/smile361/p/3853404.html