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

相关文章
|
11天前
|
网络协议 网络安全
华为openEuler欧拉系统的防火墙常用设置方法
在有防火墙的系统中,比如我们部署了一个WEB项目,我们需要给该WEB项目所需的端口放行。本文介绍了防火墙常用设置方法。
135 81
|
2月前
|
监控 安全 Linux
启用Linux防火墙日志记录和分析功能
为iptables启用日志记录对于监控进出流量至关重要
|
3月前
|
安全 网络安全 网络架构
什么是端口转发?什么是端口映射?如何设置端口映射
端口映射与端口转发是网络配置中两个常被混淆的概念。端口映射是指将外部网络请求通过路由器转发至内部网络特定主机的过程,增强了内网安全性。而端口转发则是指路由器依据端口将外部请求定向至具体设备,实现内外网通信。两者虽相似,但应用场景和原理有所不同。通过工具如花生壳,可轻松设置端口映射,实现外网访问内网服务。
515 1
|
5月前
|
机器学习/深度学习 安全 网络协议
Linux防火墙iptables命令管理入门
本文介绍了关于Linux防火墙iptables命令管理入门的教程,涵盖了iptables的基本概念、语法格式、常用参数、基础查询操作以及链和规则管理等内容。
261 73
|
4月前
|
网络协议 Ubuntu 网络安全
|
3月前
|
存储 运维 Linux
Linux防火墙firewall的使用
CentOS 7 中的 firewalld 是基于 Netfilter 的防火墙服务,支持动态配置,无需重启服务即可生效。它通过区域管理网络流量,每个区域可以设置不同的防火墙规则。默认区域为 public,可以通过命令行工具 firewall-cmd 进行管理和配置。firewalld 提供了丰富的预定义服务和区域,方便用户根据需求进行灵活配置。
61 0
|
4月前
|
开发框架 缓存 Ubuntu
dotnet开发框架+ubuntu防火墙命令+win11设置自动登录+阿里云短信发送限制
dotnet开发框架+ubuntu防火墙命令+win11设置自动登录+阿里云短信发送限制
61 3
|
6月前
|
Linux 网络安全
linux关闭方防火墙的命令
linux关闭方防火墙的命令
112 2
|
9月前
|
缓存 Linux 测试技术
安装【银河麒麟V10】linux系统--并挂载镜像
安装【银河麒麟V10】linux系统--并挂载镜像
2615 0
|
9月前
|
关系型数据库 MySQL Linux
卸载、下载、安装mysql(Linux系统centos7)
卸载、下载、安装mysql(Linux系统centos7)
280 0

热门文章

最新文章