Linux系统如何查看和设置防火墙规则(端口开放和禁用)

本文涉及的产品
云防火墙,500元 1000GB
简介: Linux系统如何查看和设置防火墙规则(端口开放和禁用)
关注原文持续更新: https://www.yundashi168.com/199.html

首先查看云服务器(Linux系统)端口是否能本地远程访问。
这里演示以阿里云服务器CentOS7为例

测试命令:

telnet ip地址 端口

在本地window系统 cmd命令窗口输入该命令。ip地址为远程服务器的公网ip地址。

命令案例:

telnet 47.114.134.179 1863

如果出现“无法打开到主机的连接。 在端口 1863: 连接失败” 就代表端口未放行。

如果出现端口未放行,怎么办?需要排查两种情况。

  • 1.查看阿里云服务器控制台是否设置了安全组规则。这个需要阿里云账号登录到阿里云,进入服务器控制台设置安全组规则。 具体教程:阿里云服务器如何设置安全组规则图文教程
  • 2.查看云服务器Linux系统是否设置了防火墙规则。查看防火墙是否关闭了端口。这个需要ssh远程连接你的linux服务器来查看和设置防火墙规则。具体教程,浏览本文。

1,查看防火墙状态

systemctl status firewalld.service

2,开启防火墙

systemctl start firewalld.service

3,关闭防火墙

systemctl stop firewalld.service

4,禁用防火墙

systemctl disable firewalld.service

5,查看防火墙已开放端口列表

firewall-cmd --list-all

案例:

[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: dhcpv6-client ssh
  ports: 3306/tcp  //已经开放的端口会在这里显示。没有显示的端口,是访问不了的。
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

6,防火墙添加端口

[root@localhost ~]# firewall-cmd --permanent --add-port=3306/tcp
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: dhcpv6-client ssh
  ports: 8080/tcp 3306/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

7,防火墙关闭端口

[root@localhost ~]# firewall-cmd --permanent --remove-port 3306/tcp
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: dhcpv6-client ssh
  ports: 8080/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

参考文献

原文地址:【猿视野】https://www.yundashi168.com/199.html

相关文章
|
2月前
|
网络协议 安全 网络安全
详细阐述 TCP、UDP、ICMPv4 和 ICMPv6 协议-以及防火墙端口原理优雅草卓伊凡
详细阐述 TCP、UDP、ICMPv4 和 ICMPv6 协议-以及防火墙端口原理优雅草卓伊凡
266 2
|
1月前
|
网络协议 Linux 网络安全
CentOS防火墙管理:查询与配置开放端口的技巧
遵循以上步骤,CentOS系统管理员能够灵活地查询和管理系统端口的开放情况,并且能适用于大多数防火墙管理场合。务必在改变防火墙规则后认真审核和测试,以确保网络安全性与服务的正常运行。
374 0
|
6月前
|
Unix Linux 编译器
windows下和linux下cmake的规则有区别吗
通过合理使用CMake的条件逻辑和平台特定的配置选项,开发者可以编写更加灵活和健壮的CMake脚本,确保项目在Windows和Linux上的一致性和可移植性。
330 76
|
10月前
|
安全 Linux 虚拟化
|
Linux 网络安全
在Linux中,要想把iptable的规则保存到一个文件中如何做?如何恢复?
在Linux中,要想把iptable的规则保存到一个文件中如何做?如何恢复?
|
10月前
|
安全 Linux 网络安全
Linux 开放的端口太多了?教你一招找出所有开放的端口,然后直接干掉!
在 Linux 系统中,端口管理至关重要。本文介绍了如何使用 `netstat`、`lsof` 和 `nmap` 等工具查找开放端口,并通过关闭相关服务、修改防火墙规则或禁用网络接口来关闭这些端口,以提高系统安全性。注意不要随意关闭重要端口,谨慎操作并备份数据。
312 3
|
Linux Python
用python扫描linux开放的端口(3种方式)
这篇文章介绍了三种使用Python实现Linux端口扫描的方法,包括基础版端口扫描、全端口扫描和多线程扫描技术。
382 16
|
Unix Linux API
Linux内核许可规则 【ChatGPT】
Linux内核许可规则 【ChatGPT】
|
监控 网络协议 Linux
在Linux中,如何实时抓取并显示当前系统中tcp 80 端口的网络数据信息?
在Linux中,如何实时抓取并显示当前系统中tcp 80 端口的网络数据信息?
|
Linux 网络安全
在Linux中,如何设置防火墙规则?
在Linux中,如何设置防火墙规则?