RHEL7、CentOS7防火墙管理
经常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防火墙管理的更多相关文章
- 【RHEL7/CentOS7防火墙之firewall-cmd命令详解】
目录 Firewalld zone firewall-cmd 开始配置防火墙策略 总结 Redhat Enterprise Linux7已默认使用firewalld防火墙,其管理工具是firewall ...
- centos7防火墙管理的变化
当我们在centos7中输入service iptables status 查看系统的防火墙状态,会出现如下错误: 网上查阅才知道centos7的防火墙管理工具变了,原来的iptables已经不用了, ...
- CentOS7防火墙管理firewalld
学习apache安装的时候需要打开80端口,由于centos 7版本以后默认使用firewalld后,网上关于iptables的设置方法已经不管用了,想着反正iptable也不太熟悉,索性直接搬官方文 ...
- Django Linux环境下部署CentOS7+Python3+Django+uWSGI+Nginx(含Nginx返回400问题处理、防火墙管理)
本文将介绍如何在Linux系统上部署Django web项目,本次部署基于下面的架构: CentOS7+ Python3.5 + Django1.11 + uWSGI + Nginx 亲测可行!!按照 ...
- RHEL7 CentOS7 检查查看精简指令
RHEL7 CentOS7 检查查看精简指令: //////////////////////////检查查看精简指令://///////////////////////////// ///////// ...
- Centos7防火墙快速开放端口配置方法
▲这篇文章主要为大家详细介绍了Centos7防火墙开放端口的快速方法,感兴趣的小伙伴们可以参考一下! Firewalld服务是红帽RHEL7系统中默认的防火墙管理工具,特点是拥有运行时配置与永久配置选 ...
- linux入门系列10--firewalld防火墙管理
上一篇文章学习了用户及文件相关权限,本篇继续学习防火墙技术. 防火墙作为公网与内网之间的保护屏障,对系统至关重要.防火墙又分为硬件防火墙和软件防火墙,主要功能都是依据设置的策略对穿越防火墙的流量进行过 ...
- CentOS7 防火墙(firewall)的操作命令
CentOS7 防火墙(firewall)的操作命令 安装:yum install firewalld 1.firewalld的基本使用 启动: systemctl start firewalld 查 ...
- CentOS7 防火墙配置firewall-cmd
firewalld(Dynamic Firewall Manager of Linux systems,Linux系统的动态防火墙管理器)服务是默认的防火墙配置管理工具. firewall-cmd 是 ...
随机推荐
- 在Linux中简单实现回收子进程
学习到wait函数了,这个函数的作用是用来回收进程.一般来说,正常退出的进程是不需要我们来专门回收的.但是进程有这两种:孤儿进程和僵尸进程. 孤儿进程: 通俗点说就是父进程先于子进程死亡.此时子进程就 ...
- Maven仓库—Nexus环境搭建及使用
使用Sonatype Nexus搭建Maven私服后如何添加第三方JAR包 http://blog.csdn.net/yanjun008/article/details/42084109 Nexus介 ...
- Haskell语言学习笔记(90)Default
安装 data-default-class $ cabal install data-default-class Installed data-default-class-0.1.2.0 Prelud ...
- Windows命令行打开常用界面
本文主要介绍Windows下命令行操作打开常用界面,使用方法为在DOS命令行下输入相关命令.可以减少多次操作界面.可以尝试在命令行执行下面提到的命令感受下,快捷键主要内容包括: 1.查看计算机的基本信 ...
- Windows上传代码到github操作指导
操作环境 Windows7(32bit) 前提条件 1.完成msysgit工具安装.下载路径:官网或百度网盘路径Git-2.15.0-32-bit.exe.安装方法为一路Next按照默认选项执行就可以 ...
- delphi 实现用户自定义通知(User Notification)
unit Form_Main; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Sy ...
- canvas入门笔记
1.Canvas的使用注意 A.要在页面中添加一对canvas标记,默认占300*150的区域 B.我们可以通过html属性‘width’,‘height’来设置canvas的宽高,不可以通过cs ...
- 吴裕雄 python 机器学习-KNN(2)
import matplotlib import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import ...
- GPS卫星定位防盗系统机芯
GPS卫星定位防盗系统机芯,一般安装在驾驶室的操作台内,包括GPS模块,安装时需要先把车门打开,并把两边的车门拆卸下来,才能拆卸驾驶仪表台,再按说明书安装GPS定位防盗机芯,同时置于4A/12V免维护 ...
- 从 mvc 到 REST
1. 理解MVC MVC是一种经典的设计模式,全名为Model-View-Controller,即模型-视图-控制器. 其中,模型是用于封装数据的载体,例如,在Java中一般通过一个简单的POJO(P ...