BGP Prefix Filters with Prefix Lists
Prefix filtering allows a network admins to permit or deny specific prefixes for each BGP neighbor, preventing BGP from inadvertently adding unwanted or illegitimate routes to the routing table. This configuration ensures that only the correct routes are accepted (inbound) or advertised (outbound). Similar to white listing, prefix filtering can be configured to only permit known or legitimate prefixes and deny others (as defined by the network policy) that are sent to or received from each BGP neighbor. The configured prefix lists should be applied to each BGP neighbor in both inbound and outbound directions.
Prefix lists can specifically allow only those prefixes that are permitted by the routing policy of a network, which is an example of white list-based filtering. If this configuration is not feasible due to the large number of prefixes, a prefix list can specifically block known undesirable prefixes (a technique known as black list filtering).
Below is the syntax for Cisco IOS to configure a prefix-list and apply it to a neighbor. To add additional lines to the prefix-list simply put in a new sequence number. Similar to ACLs, the order of prefix-lists is very important. Since prefix-lists are processed top to bottom and stop processing a route once it matches a single line, white list prefix-list administrators should always put more specific prefixes near the beginning and less specific near the end.
Router(config)# ip prefix-list {list-name [seq number] {deny|permit} network/length}
Router(config)# router bgp {AS-number}
Router(config-router)# neighbor {ip-address | neighbor-group-name} prefix-list {prefix-list name} [in|out]
The BGP neighbor at 11.1.1.1 can be managed through either white listing or black listing. With white listing, only routes from 1.1.1.0/24 and 1.2.2.0/24 are accepted. On the other hand, with blacklisting, the 1.1.1.0/24 and 1.2.2.0/24 routes are rejected while all other routes are accepted. It’s worth mentioning that in this example, the prefix-list is applied in the inbound direction to limit the routes learned from a neighbor. However, if the “out” keyword had been used, these prefix-lists would limit the routes advertised by the router.
Whitelist Filters:
Router(config)# ip prefix-list Ingress-White seq 5 permit 1.1.1.0/24 Router(config)# ip prefix-list Ingress-White seq 10 permit 1.2.2.0/24 Router(config)# ip prefix-list Ingress-White seq 15 deny 0.0.0.0/0 le 32 Router(config)# router bgp 65001
Router(config-router)# neighbor 11.1.1.1 prefix-list Ingress-White in
Blacklist Filters:
Router(config)# ip prefix-list Ingress-Black seq 5 deny 1.1.1.0/24 Router(config)# ip prefix-list Ingress-Black seq 10 deny 1.2.2.0/24 Router(config)# ip prefix-list Ingress-Black seq 15 permit 0.0.0.0/0 le 32 Router(config)# router bgp 65001
Router(config-router)# neighbor 11.1.2.1 prefix-list Ingress-Black in
Juniper routers config filters follow a slightly different approach. Juniper separates the prefix list from the corresponding action, which is achieved through the use of a prefix-list object. This object contains a grouped list of all the desired prefixes. Subsequently, a policy-statement is created, which can include multiple term statements. Each term statement determines whether to permit or deny the prefix-list objects. Finally, the policy-statement is applied in the desired direction, either inbound or outbound, to the intended BGP group:
user@Router# edit policy-options prefix-list [list-name] user@Router# set [prefix-address]
user@Router# edit policy-options policy-statement [policy-name] term [term-name]] user@Router# set from prefix-list [list-name]
user@Router# set then accept/reject
user@Router# edit protocols bgp group [group-name] user@Router# set type [internal/external]
user@Router# set local-address [local-ip-address] user@Router# set [import|export] [import/export-policy] user@Router# set neighbor [neighbor-ip-address]
Prefix Filters with AS Access Lists
BGP Prefix Filters with Autonomous System (AS) path access lists can be used to filter illegitimate prefixes from the BGP routing tables. AS path access allows network admins to filter inbound and outbound prefixes based on the AS number. When combined, AS Path Access Lists and Prefix Lists create a robust set of BGP route filters, ensuring only desired traffic routes and preventing unwanted routes.
The first step to configure an AS-path filter on Cisco routers is to create an AS-path ACL. This ACL utilizes regular expressions for AS-path matching. Once the AS-path ACL is generated, it can be associated with the desired BGP neighbor using the following syntax.
Router(config)# ip as-path access-list number {permit|deny} regexp
Router(config-router)# neighbor ip-address filter-list number {in/out}
Sample for two AS paths:
Router(config)# ip as-path access-list 1 permit ^1000$
Router(config)# ip as-path access-list 2 permit ^$
Router(config-router)# neighbor 11.1.1.1 filter-list 1 in
Router(config-router)# neighbor 11.1.1.1 filter-list 2 out
Juniper AS path regular expressions:
Define the desired regular expressions separately from the policy by creating as-path objects. Utilize the created as-path objects when creating policies. Each policy can accept or reject different AS paths and may have multiple terms. Link the policies to a BGP group, specifying the inbound or outbound direction.
Simplified syntax:
user@Router# edit policy-options
user@Router# set as-path [as-path-name] [regular-expression]
user@Router# edit policy-options policy-statement [policy-name] term [term-name] user@Router# set from as-path [as-path-name]
user@Router# set then accept/reject
user@Router# edit protocols bgp
user@Router# set group [group-name] import [import-policy] user@Router# set group [group-name] export [export-policy]
Sample for two AS paths:
user@Router# edit policy-options
user@Router# set as-path From-AS-1000 “^1000$” user@Router# set as-path From-AS-Local “1005”
user@Router# edit policy-options policy-statement Match-AS-1000 term 1
user@Router# set from as-path From-AS-1000
user@Router# set then accept
user@Router# edit policy-options policy-statement Match-AS-Local term 1
user@Router# set from as-path From-AS-Local
user@Router# set then accept
user@Router# edit policy-options policy-statement Match-AS-Local term 2
user@Router# set then reject
user@Router# edit protocols bgp
user@Router# set group AS-1000 import Match-AS-1000
user@Router# set group AS-1000 export Match-AS-Local
BGP Neighboring Authentication
Authenticating between BGP neighbors confirms the legitimacy and trustworthiness of the neighbors. It also verifies their communication and ensures that only routes learned from trusted neighbors are added to the routing table. Without BGP authentication, a malicious user can spoof a neighbor’s IP address, establish BGP connections, and potentially manipulate BGP routing tables.
To enable neighbor authentication, the authentication password must be enabled on both sides of the peering session. It is important to adhere to the local password policy in terms of length and complexity. For optimal security, ensure that this password is shared out-of-band.
Router(config-router)# neighbor ip-address password string
Juniper offers a more advanced configuration option for BGP neighbor authentication. Key differences include authentication algorithms and setting a key start time. The key start time allows for pre-configuration of BGP sessions on both sides before switching to new keys at a specified time. This reduces downtime and maintains an active session during BGP authentication configuration. The initial step in configuring BGP authentication in Juniper involves defining a key-chain object and entering a strong password for neighbor authentication. The subsequent step is to associate the key-chain with a BGP group, effectively enabling BGP authentication:
user@Router# edit security authentication-key-chains key-chain [key-chain-name]
user@Router# set key [key-identifier] secret [password]
user@Router# set key [key-identifier] start-time [YYYY-MM-DD.HH:MM)
user@Router# edit protocols bgp group [group-name]
user@Router# set authentication-key-chain [key-chain-name]
user@Router# set authentication-algorithm [md5|hmac-sha-1-96|aes-128-cmac-96]
Time to Live (TTL) Security
The BGP TTL security check protects BGP against DoS attacks and route manipulation attempts. When the security check is enabled, it sets the expected final TTL value for incoming packets from each external BGP neighbor. As an IP packet moves towards its final destination, its TTL value decreases for each router hop. The BGP TTL security check compares the received packet’s TTL value to the expected TTL value for the BGP session. If the TTL value is less than the expected value, the packet is dropped. If the TTL value is equal to or greater than the expected value, the check is passed and the session establishes.
Cisco Sample:
Router(config)# router bgp as-number
Router(config-router)# neighbor ip-address ttl-security hops hop-count
Juniper Sample:
user@Router# edit protocols bgp group [group-name]
user@Router# set neighbor [neighbor-ip-address]
user@Router# set multihop ttl [ttl-value]
Enabling Logging
The “bgp log-neighbor-changes” command in Cisco devices enables logging of BGP neighbor status changes (up or down) and resets for troubleshooting network connectivity problems and measuring network stability. Unexpected neighbor resets may indicate high error rates or packet loss in the network, requiring further investigation.
To display the log for neighbor changes, use the “show logging” command. It is considered a best practice to send all logging to a syslog server. In this example, we provide the syntax to enable local logging. Please refer to the vendor guidance to configure logging to a syslog server.
Router(config-router)# bgp log-neighbor-changes
Juniper devices procedures are similar. The only command that is required is set log- updown within the protocol bgp configuration.
user@Router# edit protocol bgp
user@Router# set log-updown
Most Importantly, BGP Threats
BGP relies on the Transmission Control Protocol (TCP) as its transport protocol, making it susceptible to TCP-based attacks. Here are the most common BGP threats:
- Denial of Service (DoS): A malicious host floods a BGP neighbor with unexpected or unwanted traffic, overwhelming control plane resources and hindering the processing of legitimate BGP traffic.
- Route Manipulation: A malicious host alters the contents of a BGP routing table, diverting sender traffic and preventing it from reaching its intended destination without the sender’s knowledge. For instance, Pakistani ISPs once injected a BGP route for YouTube®, leading users’ traffic to nowhere. This manipulated route spread across the Internet via neighboring ISPs, resulting in the inaccessibility of YouTube until the route was removed.
- Route Hijacking: A rogue BGP neighbor deceitfully advertises a victim’s networks to redirect a portion or all of the victim’s traffic toward itself. In 2014, Turkish ISPs hijacked Google’s DNS servers, effectively blocking Turkish citizens’ access to social media sites.
- Misconfiguration (non-malicious): Unintentional misconfiguration of a BGP router can disrupt the Internet’s BGP routing table, potentially causing network outages and unauthorized access to network traffic.