bgpgrep
Search BGP routing tables
TLDR
List all routes
List routes received from a specific peer, determined by the peer's AS number
List routes received from a specific peer, determined by the peer's IP address
List routes which have certain ASNs in their AS path
List routes that lead to a specific address
List routes that have communities from a specific AS
SYNOPSIS
bgpgrep [OPTIONS] [PATTERNS]
Common usage examples:
birdc show route | bgpgrep [OPTIONS]
bgpgrep [OPTIONS] -f <FILE> [PATTERNS]
PARAMETERS
-p <prefix>, --prefix <prefix>
Matches routes that advertise the specified IP prefix (e.g., 192.168.1.0/24).
-a <AS_PATH_REGEX>, --as-path <AS_PATH_REGEX>
Matches routes whose AS path attribute matches the given regular expression (e.g., _65001_ for routes traversing AS 65001).
-n <next_hop>, --next-hop <next_hop>
Matches routes with a specific next-hop IP address.
-c <community>, --community <community>
Matches routes carrying a specific BGP community string (e.g., 65535:666).
-o <origin_as>, --origin-as <origin_as>
Matches routes that originated from a specific AS number.
-l, --long
Displays matching routes in a more detailed, long output format.
-j, --json
Outputs the matching routes in JSON format, if supported by the specific implementation.
-v, --invert-match
Inverts the match, selecting routes that do not match the specified patterns.
-i, --ignore-case
Performs case-insensitive matching for patterns.
-f <file>, --file <file>
Reads BGP routing information from the specified <file> instead of standard input.
DESCRIPTION
bgpgrep is a specialized command-line utility designed to search, filter, and display BGP (Border Gateway Protocol) routing information. Unlike general-purpose text search tools like grep, bgpgrep understands the structured nature of BGP routes, allowing users to query routes based on specific BGP attributes such as prefixes, AS paths, next-hops, BGP communities, origin AS, and more.
It is particularly useful for network engineers and administrators to diagnose routing issues, verify routing policies, analyze BGP updates, and extract specific routing information from large BGP routing tables or BGP dumps. It often works in conjunction with routing daemon outputs, like birdc show route from the BIRD routing daemon, by processing their standard output or files containing BGP routing data.
CAVEATS
bgpgrep is not a standard core Linux command and requires installation of specific routing software (e.g., BIRD Internet Routing Daemon or Free Range Routing).
The exact set of options, their syntax, and behavior can vary significantly between different implementations or versions. Users should always consult the official documentation or man pages for the specific bgpgrep version they are using.
It is primarily designed for parsing structured BGP data and is not a general-purpose text processing tool.
INPUT DATA FORMATS
bgpgrep is designed to parse BGP routing information, typically from human-readable output of BGP daemon commands. Common input sources include the standard output of commands like birdc show route, show ip bgp (from FRR or Cisco/Juniper devices), or files containing BGP RIB dumps in a textual format.
INTEGRATION WITH SCRIPTING
Given its command-line interface and capability to output structured data (especially with options like -j or -l), bgpgrep is frequently employed in shell scripts for automated BGP route analysis, network monitoring, and generating reports, making it a valuable tool for network automation.
HISTORY
bgpgrep emerged from the growing need for efficient analysis of large BGP routing tables. As BGP became the dominant routing protocol for the Internet, the volume of routing information processed by network devices increased dramatically. Standard text processing tools like grep were inadequate for intelligently filtering and querying structured BGP attributes.
Consequently, specialized tools like bgpgrep were developed, often as part of open-source routing daemon projects such as the BIRD project. Its development aimed to provide network engineers with a powerful and intuitive way to query BGP data, facilitating debugging, policy validation, and network monitoring tasks in complex BGP environments.