博客
关于我
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/

你可能感兴趣的文章
MySQL 深度分页性能急剧下降,该如何优化?
查看>>
MySQL 添加列,修改列,删除列
查看>>
mysql 添加索引
查看>>
MySQL 添加索引,删除索引及其用法
查看>>
mysql 状态检查,备份,修复
查看>>
MySQL 用 limit 为什么会影响性能?
查看>>
MySQL 用 limit 为什么会影响性能?有什么优化方案?
查看>>
MySQL 用户权限管理:授权、撤销、密码更新和用户删除(图文解析)
查看>>
mysql 用户管理和权限设置
查看>>
MySQL 的 varchar 水真的太深了!
查看>>
mysql 的GROUP_CONCAT函数的使用(group_by 如何显示分组之前的数据)
查看>>
MySQL 的instr函数
查看>>
MySQL 的mysql_secure_installation安全脚本执行过程介绍
查看>>
MySQL 的Rename Table语句
查看>>
MySQL 的全局锁、表锁和行锁
查看>>
mysql 的存储引擎介绍
查看>>
MySQL 的存储引擎有哪些?为什么常用InnoDB?
查看>>
Mysql 知识回顾总结-索引
查看>>
Mysql 笔记
查看>>
MySQL 精选 60 道面试题(含答案)
查看>>