Linux查看防火墙
·云扬·
于 2025-01-22 10:19:54 发布
阅读量978
收藏 5
点赞数 17
分类专栏: 运维 文章标签: linux 网络 服务器
版权
运维
专栏收录该内容
2 篇文章0 订阅
订阅专栏
在 Linux 系统中,防火墙通常由 iptables、firewalld 或 ufw 管理。以下是查看防火墙状态的常用方法:
1. 检查防火墙是否启用
1.1 使用 systemctl 检查防火墙服务状态
对于 firewalld:
sudo systemctl status firewalld
1
如果显示 active (running),表示 firewalld 正在运行。如果显示inactive (dead),表示firewalld未运行。
对于 ufw(Ubuntu/Debian):
sudo systemctl status ufw
1
如果显示 active (running),表示 ufw 正在运行。
对于 iptables:
sudo systemctl status iptables
1
如果显示 active (running),表示 iptables 正在运行。
1.2 查看防火墙规则
1.2.1 使用 firewalld
查看当前区域和规则:
sudo firewall-cmd --list-all
1
输出示例:
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: ssh dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
1
2
3
4
5
6
7
8
9
10
11
12
13
查看开放的端口:
sudo firewall-cmd --list-ports
1
1.2.2 使用 ufw
查看防火墙状态和规则:
sudo ufw status verbose
1
输出示例:
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
1
2
3
4
5
1.2.3 使用 iptables
查看所有规则:
sudo iptables -L -n -v
1
输出示例:
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
1
2
3
4
5
6
7
8
9
3. 检查防火墙是否阻止了特定端口
3.1 使用 nmap
安装 nmap:
sudo yum install nmap # CentOS/RHEL
sudo apt install nmap # Ubuntu/Debian
1
2
扫描本地端口:
nmap -sT -p 22,80,3306 localhost
1
输出示例:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-10-01 12:00 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00010s latency).
PORT STATE SERVICE
22/tcp open ssh
80/tcp closed http
3306/tcp closed mysql
1
2
3
4
5
6
7
4. 临时关闭防火墙
4.1 关闭 firewalld
sudo systemctl stop firewalld
1
4.2 关闭 ufw
sudo ufw disable
1
4.3 清空 iptables 规则
sudo iptables -F
1
5. 永久关闭防火墙
5.1 禁用 firewalld
sudo systemctl disable firewalld
1
5.2 禁用 ufw
sudo ufw disable
1
5.3 清空并保存 iptables 规则
sudo iptables -F
sudo service iptables save
1
2
6. 总结
使用 systemctl 检查防火墙服务状态。
使用 firewall-cmd、ufw 或 iptables 查看防火墙规则。
使用 nmap 检查端口是否开放。
如果需要,可以临时或永久关闭防火墙。
根据你的需求选择合适的方法查看或管理防火墙。如果问题仍然存在,请提供更多上下文信息(如操作系统版本、防火墙工具等),以便进一步分析。
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/gaosw0521/article/details/145297874
评论(0)