博客
关于我
linux防火墙查看状态firewall、iptable
阅读量:150 次
发布时间:2019-02-28

本文共 1544 字,大约阅读时间需要 5 分钟。

CentOS7 防火墙配置指南

CentOS7 的防火墙配置与之前版本存在显著差异,主要使用 firewall 替代了之前的 iptables。以下将详细介绍 CentOS7 下的防火墙配置方法。


一、iptables 防火墙

1. iptables 基本操作

查看防火墙状态

service iptables status

停止防火墙

service iptables stop

启动防火墙

service iptables start

重启防火墙

service iptables restart

####永久关闭防火墙

chkconfig iptables off

永久关闭后重启

chkconfig iptables on

2. 开启 80 端口

打开防火墙配置文件

vim /etc/sysconfig/iptables

添加 80 端口规则

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

保存并重启防火墙

service iptables restart

二、firewall 防火墙

1. 查看 firewall 服务状态

systemctl status firewalld
  • 状态显示为 active (running) 则表示 firewall 服务已启动。
  • 状态显示为 inactive (dead) 则表示 firewall 服务已停止。

2. 查看 firewall 状态

firewall-cmd --state

3. 操作 firewall 服务

启动 firewall 服务

service firewalld start

重启 firewall 服务

service firewalld restart

关闭 firewall 服务

service firewalld stop

永久关闭 firewall 服务

systemctl disable firewalld

4. 查看防火墙规则

firewall-cmd --list-all

5. 端口管理

查询端口状态

firewall-cmd --query-port=8080/tcp

打开 80 端口

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

移除 8080 端口

firewall-cmd --permanent --remove-port=8080/tcp

重启防火墙

firewall-cmd --reload

3. firewall 常用命令参数说明

  • --permanent:表示设置为持久有效。
  • --add-port:用于添加指定端口。
  • --remove-port:用于移除指定端口。
  • --query-port:用于查询指定端口状态。

4. 切换防火墙类型

1. 关闭 firewall 并使用 iptables

systemctl stop firewalldsystemctl disable firewalld

2. 安装 iptables 服务

yum install iptables-services

3. 修改防火墙配置文件

vim /etc/sysconfig/iptables

添加常用端口(如 80、8080、3306 等)

-A INPUT -m state --state NEW -m tcp -p tcp --dport [端口号] -j ACCEPT

保存并重启防火墙

systemctl restart iptables.service

5. 防火墙开机启动设置

systemctl enable iptables.service

转载地址:http://knyj.baihongyu.com/

你可能感兴趣的文章
MS Edge浏览器“STATUS_INVALID_IMAGE_HASH“兼容性问题
查看>>
ms sql server 2008 sp2更新异常
查看>>
MS UC 2013-0-Prepare Tool
查看>>
MSBuild 教程(2)
查看>>
msbuild发布web应用程序
查看>>
MSB与LSB
查看>>
MSCRM调用外部JS文件
查看>>
MSCRM调用外部JS文件
查看>>
MSEdgeDriver (Chromium) 不适用于版本 >= 79.0.313 (Canary)
查看>>
MsEdgeTTS开源项目使用教程
查看>>
msf
查看>>
MSSQL数据库查询优化(一)
查看>>
MSSQL数据库迁移到Oracle(二)
查看>>
MSSQL日期格式转换函数(使用CONVERT)
查看>>
MSTP多生成树协议(第二课)
查看>>
MSTP是什么?有哪些专有名词?
查看>>
Mstsc 远程桌面链接 And 网络映射
查看>>
Myeclipse常用快捷键
查看>>
MyEclipse更改项目名web发布名字不改问题
查看>>
MyEclipse用(JDBC)连接SQL出现的问题~
查看>>