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

你可能感兴趣的文章
MSTP多生成树协议(第二课)
查看>>
MSTP是什么?有哪些专有名词?
查看>>
Mstsc 远程桌面链接 And 网络映射
查看>>
Myeclipse常用快捷键
查看>>
MyEclipse更改项目名web发布名字不改问题
查看>>
MyEclipse用(JDBC)连接SQL出现的问题~
查看>>
mt-datetime-picker type="date" 时间格式 bug
查看>>
myeclipse的新建severlet不见解决方法
查看>>
MyEclipse设置当前行背景颜色、选中单词前景色、背景色
查看>>
Mtab书签导航程序 LinkStore/getIcon SQL注入漏洞复现
查看>>
myeclipse配置springmvc教程
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
MySQL
查看>>
MySQL
查看>>
mysql
查看>>
MTK Android 如何获取系统权限
查看>>