Linux CentOS 7 防火墙/端口设置

本文涉及的产品
云防火墙,500元 1000GB
简介: Linux CentOS 7 防火墙/端口设置

CentOS升级到7之后用firewall代替了iptables来设置Linux端口,

下面是具体的设置方法:

[]:选填

<>:必填

[<zone>]:作用域(block、dmz、drop、external、home、internal、public、trusted、work)

<port>:端口号

[-<port>]:或者端口范围

<protocol>:端口协议(tcp、udp)

[<seconds>]:过期时间,使用N秒后自动关闭(秒)

[--permanent]:永久设置,在重启后依然保证设置可用,如果不加此项,重启后端口会恢复关闭状态

注:设置端口后要重启防火墙使其生效 firewall-cmd --reload

1、检查端口状态

yes:已开通

no:未开通

firewall-cmd --query-port=<port>[-<port>]/<protocol>

firewall-cmd [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

firewall-cmd [--permanent] [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

image.png

查看已开放的端口

firewall-cmd --zone=public --list-ports

image.png

 

2、启用端口

success:执行成功

warning:警告xxx

firewall-cmd --add-port=<port>[-<port>]/<protocol>

firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]

firewall-cmd [--permanent] [--zone=<zone>] --add-port=<port>[-<port>]/<protocol>

image.png

 

3、禁用端口

success:执行成功

warning:警告xxx

firewall-cmd --remove-port=<port>[-<port>]/<protocol>

firewall-cmd [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>

firewall-cmd [--permanent] [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>

image.png

 

4、防火墙相关

--reload:不改变状态的条件下重启防火墙

--complete-reload:状态信息将会丢失,当防火墙有问题时可以使用,如,状态信息和防火墙规则都正常却无法建立任何链接的情况等

firewall-cmd --reload

firewall-cmd --complete-reload

查看防火墙状态

firewall-cmd --state

查看、打开、关闭应急模式(应急模式阻断所有网络连接,防止出现紧急状况)

firewall-cmd --query-panic

firewall-cmd --panic-on

firewall-cmd --panic-off

打开、关闭、重启防火墙

systemctl stop firewalld

systemctl start firewalld

systemctl restart firewalld

开启/关闭 开机自启动防火墙

systemctl enable firewalld

systemctl disable firewalld

 

相关文章
|
30天前
|
网络协议 Linux
Linux查看端口监听情况,以及Linux查看某个端口对应的进程号和程序
Linux查看端口监听情况,以及Linux查看某个端口对应的进程号和程序
133 2
|
1月前
|
安全 Linux 应用服务中间件
在Linux中,包过滤防火墙与代理应用防火墙有什么区别?有哪些相应的产品?
在Linux中,包过滤防火墙与代理应用防火墙有什么区别?有哪些相应的产品?
|
26天前
|
机器学习/深度学习 安全 网络协议
Linux防火墙iptables命令管理入门
本文介绍了关于Linux防火墙iptables命令管理入门的教程,涵盖了iptables的基本概念、语法格式、常用参数、基础查询操作以及链和规则管理等内容。
185 73
|
3天前
|
Linux Python
用python扫描linux开放的端口(3种方式)
这篇文章介绍了三种使用Python实现Linux端口扫描的方法,包括基础版端口扫描、全端口扫描和多线程扫描技术。
27 15
|
3天前
|
消息中间件 Java Linux
linux 之centos7安装kafka;;;;;待补充,未完成
linux 之centos7安装kafka;;;;;待补充,未完成
|
30天前
|
Linux 网络安全
linux关闭方防火墙的命令
linux关闭方防火墙的命令
38 2
|
1月前
|
监控 网络协议 Linux
在Linux中,如何实时抓取并显示当前系统中tcp 80 端口的网络数据信息?
在Linux中,如何实时抓取并显示当前系统中tcp 80 端口的网络数据信息?
|
1月前
|
网络协议 安全 应用服务中间件
在Linux中,Tomcat8005、8009、8080三个端口的含义?
在Linux中,Tomcat8005、8009、8080三个端口的含义?
|
1月前
|
网络协议 Linux 网络安全
在Linux中,如何将本地 80 端口的请求转发到 8080 端口?当前主机 IP 为10.0.0.104。
在Linux中,如何将本地 80 端口的请求转发到 8080 端口?当前主机 IP 为10.0.0.104。
|
1月前
|
Linux 网络安全
在Linux中,如何设置防火墙规则?
在Linux中,如何设置防火墙规则?