← ClaudeAtlas

diag-network-port-unreachlisted

端口不可达全链诊断。从 DNS 解析 → TCP connect → iptables/firewalld 规则 → 服务监听状态 → 路由表 → SELinux/AppArmor,逐层排查并输出结构化报告。
seed-forge/harness-ai-kit · ★ 22 · AI & Automation · score 74
Install: claude install-skill seed-forge/harness-ai-kit
# Network Port Unreachable Full-Chain Diagnostics ## 用途 当用户报告某个端口/服务不可达、连接超时或被拒绝时触发。 ## 输入 - 目标 host:port - 可选:源机器、协议(TCP/UDP) ## 输出 - 端口连通性诊断报告 + 修复建议 ## 诊断步骤 ### Step 1: DNS 解析 ```bash # 确认目标地址能解析 dig +short {hostname} nslookup {hostname} getent hosts {hostname} # 如果是 IP 则跳过 DNS ``` ### Step 2: TCP 连通性测试 ```bash # 基础连通 nc -zv {host} {port} -w 5 # 或 timeout 5 bash -c "echo > /dev/tcp/{host}/{port}" 2>&1 # 多端口批量测试 for p in {port_list}; do nc -zv {host} $p -w 3 2>&1; done # 路由追踪 traceroute -T -p {port} {host} ``` ### Step 3: 目标端服务监听 ```bash # 服务是否在监听 ss -tlnp | grep :{port} # 或 netstat -tlnp | grep :{port} # 绑定地址(127.0.0.1 vs 0.0.0.0) ss -tlnp | grep :{port} | awk '{print $4}' ``` ### Step 4: 防火墙规则 ```bash # iptables iptables -L INPUT -n --line-numbers | grep {port} iptables -L FORWARD -n --line-numbers | grep {port} # firewalld firewall-cmd --list-all firewall-cmd --query-port={port}/tcp # nftables nft list ruleset | grep {port} # ufw ufw status numbered | grep {port} ``` ### Step 5: 路由与 NAT ```bash # 路由表 ip route get {target_ip} ip route show table all | grep {subnet} # NAT 规则(端口转发场景) iptables -t nat -L PREROUTING -n --line-numbers iptables -t nat -L DNAT -n --line-numbers # Windows portproxy(如果涉及 Windows 转发) netsh interface portproxy show all ``` ## 输出模板 ``` Port Connectivity Diagnosis Report ════════════════════════════���═══════════ Target: {host}:{port} Protocol: {tcp/udp} Source: {source_host} Time: {timestamp} DNS Resolution {h