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

你可能感兴趣的文章
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>