Communitygithub.com

網路 BGP 診斷

僅供診斷的 BGP 故障排除模式,涵蓋鄰居狀態、路由交換、前綴策略、AS 路徑檢查與安全證據收集。適用於 BGP 鄰居中斷、路由遺失、或需要檢查前綴策略與 AS 路徑時。

網路 BGP 診斷 是什麼?

此技能專為 BGP 網路故障排除設計,提供一套唯讀的診斷工作流程。當 BGP 連線中斷、翻動、雖已建立但缺少路由、或廣告了非預期的前綴時,即可使用此技能。它涵蓋了從檢查 BGP 摘要、鄰居狀態、傳輸層連通性,到深入檢視路由策略、前綴列表、AS 路徑正規表示式的完整步驟。此技能也包含一個 Python 正規表示式解析器,可從 BGP 摘要輸出中擷取鄰居、遠端 AS、狀態和接收前綴數等結構化資料。支援的平台包括一般支援 BGP 的網路設備(例如 Cisco IOS),並特別提醒注意 VRF、位址系列和更新來源的差異。此技能明確區分唯讀證據收集與應在變更窗口中執行的變更動作(如清除連線或修改策略),並列出常見的反模式以避免錯誤假設。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/network-bgp-diagnostics

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

網路 BGP 診斷 是做什麼的?

當 BGP 連線中斷、翻動、已建立但缺少路由、或廣告了非預期的前綴時,請使用此技能。預設工作流程為唯讀證據收集;政策和重置操作應在經過審查的變更窗口中進行。

使用時機

  • BGP 鄰居卡在 Idle、Connect、Active、OpenSent 或 OpenConfirm 狀態。
  • 連線已建立,但預期的前綴遺失。
  • route-map、prefix-list、max-prefix 限制或 AS 路徑政策可能正在過濾路由。
  • 您需要 BGP 變更前後的證據。
  • 您正在審查解析 BGP 摘要輸出的自動化程式。

唯讀故障排除流程

  1. 確定確切的鄰居、位址系列、VRF 以及本端和遠端 ASN。
  2. 擷取摘要狀態和上次重設原因。
  3. 驗證對等端來源地址的可達性。
  4. 在假設傳輸故障之前,先檢查路由策略引用。
  5. 在平台支援的命令中,比較廣告、接收和安裝的路由。
show bgp summary
show bgp neighbors <peer>
show ip route <peer>
show tcp brief | include <peer>|:179
show logging | include BGP|<peer>
show running-config | section router bgp
show ip prefix-list
show route-map

當設備使用 VRF、IPv6、VPNv4 或 EVPN 時,請使用平台專屬的位址系列命令。不要假設為全域 IPv4 單播。

狀態解讀

狀態優先檢查項目
Established 且帶有前綴計數路由交換正常;檢查策略和路由表選擇
Established 但前綴為零檢查入站策略、max-prefix、廣告路由和 AFI/SAFI
ActiveTCP 連線未完成;檢查路由、來源、ACL 和對等端可達性
ConnectTCP 連線正在進行;檢查路徑和遠端監聽程式
OpenSent/OpenConfirmTCP 正常;檢查 ASN、驗證、計時器、能力和日誌
Idle鄰居可能被停用、設定遺失、被策略阻擋、或處於退避計時器狀態

傳輸檢查

ping <peer> source <local-source>
traceroute <peer> source <local-source>
show ip route <peer>
show bgp neighbors <peer> | include BGP state|Last reset|Local host|Foreign host

如果對等端來源是環回介面,請確認雙向路由皆可到達環回地址,且鄰居設定使用了預期的更新來源。

避免以關閉 ACL 或防火牆策略作為診斷捷徑。應先讀取命中計數器、日誌和路徑狀態。

路由策略檢查

show bgp neighbors <peer> advertised-routes
show bgp neighbors <peer> routes
show ip prefix-list <name>
show route-map <name>
show bgp <prefix>

某些平台需要額外設定才能使用 received-routes。在事件故障排除期間,除非操作員核准變更,否則請勿新增該設定。

AS 路徑與前綴審查

show bgp regexp _65001_
show bgp regexp ^65001$
show bgp <prefix>
show bgp neighbors <peer> advertised-routes | include Network|Path|<prefix>

請謹慎使用 AS-path 正規表達式。_65001_ 會將 AS 65001 視為一個 token 進行匹配。單純的 65001 可能匹配到更長的 ASN 或不相關的文字。

解析器模式

import re
from typing import Any

BGP_SUMMARY_RE = re.compile(
    r"^(?P<neighbor>\d{1,3}(?:\.\d{1,3}){3})\s+"
    r"(?P<version>\d+)\s+"
    r"(?P<remote_as>\d+)\s+"
    r"(?P<msg_rcvd>\d+)\s+"
    r"(?P<msg_sent>\d+)\s+"
    r"(?P<table_version>\d+)\s+"
    r"(?P<input_queue>\d+)\s+"
    r"(?P<output_queue>\d+)\s+"
    r"(?P<uptime>\S+)\s+"
    r"(?P<state_or_prefixes>\S+)$",
    re.M,
)

def parse_bgp_summary(raw: str) -> list[dict[str, Any]]:
    rows = []
    for match in BGP_SUMMARY_RE.finditer(raw):
        state_or_prefixes = match.group("state_or_prefixes")
        if state_or_prefixes.isdigit():
            state = "Established"
            prefixes_received = int(state_or_prefixes)
        else:
            state = state_or_prefixes
            prefixes_received = None
        rows.append({
            "neighbor": match.group("neighbor"),
            "remote_as": int(match.group("remote_as")),
            "state": state,
            "prefixes_received": prefixes_received,
            "uptime": match.group("uptime"),
        })
    return rows

在可能的情況下,優先使用結構化的解析器輸出,但請同時將原始輸出與事件記錄一同儲存,因為 BGP 摘要格式因平台和位址系列而異。

僅限變更窗口

以下動作可能影響路由,不應作為自動診斷建議:

  • 清除 BGP 連線。
  • 變更鄰居驗證、計時器、更新來源、route-map 或 prefix-list。
  • 啟用額外的 received-route 儲存。
  • 放寬防火牆、ACL 或控制平面策略。

如果核准重設,請優先使用平台支援的最小影響軟重設或路由重新整理選項,並記錄為何此操作是安全的。

反模式

  • 假設 Active 狀態總是代表遠端端已中斷。
  • 忽略 VRF、位址系列或更新來源的差異。
  • 使用沒有 token 邊界的寬鬆 AS-path 正規表達式。
  • 在讀取上次重設原因和日誌之前,就對對等端進行硬重設。
  • 將缺少 received-routes 輸出視為沒有路由抵達的證明。

參見

  • 技能:cisco-ios-patterns
  • 技能:network-config-validation
  • 技能:network-interface-health

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相關技能