洞察时代脉搏,纵览信息资讯
给你一条“尽可能全平台自动识别防火墙并放开 1–65535 TCP/UDP”的一键命令”(Linux 通用思路版)。
bash -c '
if command -v firewall-cmd >/dev/null 2>&1; then
firewall-cmd --permanent --add-port=1-65535/tcp
firewall-cmd --permanent --add-port=1-65535/udp
firewall-cmd --reload
elif command -v ufw >/dev/null 2>&1; then
ufw allow proto tcp to any
ufw allow proto udp to any
ufw reload
elif command -v nft >/dev/null 2>&1; then
nft list table inet filter >/dev/null 2>&1 || nft add table inet filter
nft list chain inet filter input >/dev/null 2>&1 || nft add chain inet filter input "{ type filter hook input priority 0 ; policy accept ; }"
nft add rule inet filter input tcp dport 1-65535 accept 2>/dev/null || true
nft add rule inet filter input udp dport 1-65535 accept 2>/dev/null || true
elif command -v iptables >/dev/null 2>&1; then
iptables -C INPUT -p tcp --dport 1-65535 -j ACCEPT 2>/dev/null || iptables -A INPUT -p tcp --dport 1-65535 -j ACCEPT
iptables -C INPUT -p udp --dport 1-65535 -j ACCEPT 2>/dev/null || iptables -A INPUT -p udp --dport 1-65535 -j ACCEPT
else
echo "No supported firewall tool found"
fi'它会自动判断你系统用的防火墙:
→ 用 firewall-cmd
→ 用 ufw allow
→ 用 nft add rule
→ 用 iptables -A
Linux 没有统一防火墙 API,所以这是“兼容折中方案”。
某些系统可能报错,例如:
table 不存在
chain 不存在
👉 这是正常情况(不同发行版结构不同)
即使你执行成功,还可能被挡:
阿里云安全组
AWS Security Group
腾讯云防火墙
👉 这条命令管不了云层
要确认“是否真的全端口开放”,不能只看你执行成功没,而要从防火墙规则 + 外部探测 + 本机监听三层一起看。
我给你一套最准确的检查方法(按优先级)。
firewall-cmd --list-all
重点看这一行:
ports: 1-65535/tcp 1-65535/udp
👉 有这个 = 已放开
ufw status verbose
如果看到:
To Action From -- ------ ---- Anywhere ALLOW Anywhere
或:
1:65535/tcp ALLOW
👉 说明已放开
nft list ruleset
重点找:
tcp dport 1-65535 accept udp dport 1-65535 accept
iptables -L -n -v
或者更清晰:
iptables -S
找:
--dport 1:65535 -j ACCEPT
在另一台机器执行:
nmap -p 1-65535 你的服务器IP
或快速扫:
nmap -p- 你的IP
👉 结果判断:
open = 端口真的开
filtered = 被防火墙/云安全组拦了
closed = 服务没监听
ss -tulnp
或:
netstat -tulnp
👉 注意:
这一步只能看到“程序有没有在监听端口”
❌ 不代表防火墙放没放行
很多人以为“开了端口”,但其实:
阿里云 / 腾讯云 / AWS → 直接拦截
比如:
3306 没启动 MySQL
80 没启动 Nginx
没 reload
规则在错误 table/chain
被后续规则覆盖
firewall-cmd --list-ports
nft list ruleset | grep -E "dport 1-65535"
iptables -S | grep 65535
👉 判断是否“全端口开放”,标准是:
本文链接:https://www.sxlog.com/post/1993.html
商务合作 - Email:admin@sxlog.com