Day 12: BGP Between Two Sites
Goal: Two sites with their own AS numbers exchange their networks via BGP, over two links. You experience why BGP does nothing at all without filters, write prefix-lists and route-maps, decide which link is the primary path and which the backup, and catch a neighbor announcing foreign networks · Duration: approx. 90 min · Prerequisite: Day 10
Briefing
- OSPF is built for your own network: all routers trust each other and know the whole map. Between organizations, sites with separate administration, or toward the provider, you speak BGP. Each side has an AS number (Autonomous System) and decides for itself what it accepts and passes on.
- BGP has no map, only announcements: “You reach the network 10.20.1.0/24 via me, the path leads through AS 65002.” The list of AS numbers along the way is called the AS path; it prevents loops and is a criterion for the best path.
- Because anyone can announce anything, every BGP session needs a filter. prefix-lists describe networks, route-maps use them to decide what gets through and can change attributes.
Site A, AS 65001 Site B, AS 65002
ha .10 ── eth0 ┌────┐ eth1 10.99.1.0/30 (circuit 1) eth1 ┌────┐ eth0 ── hb .10
10.10.1.0/24 │ a1 ├────────────────────────────────────┤ b1 │ 10.20.1.0/24
10.10.2.0/24 ──┤lan2│ eth2 10.99.2.0/30 (circuit 2) eth2 │ │
(dummy) └────┴────────────────────────────────────┴────┘
AS numbers from 64512 to 65534 are reserved for private use, like the private IP addresses. Link 1 is the fast primary link, link 2 the backup.
Drill 1: Two Sites
Site A has a second network 10.10.2.0/24 without hosts;
a dummy device is enough so that there is a route to it (Day 1).
# on netz
sudo ip netns add a1
sudo ip netns add b1
sudo ip netns add ha
sudo ip netns add hb
for n in a1 b1 ha hb; do sudo ip -n $n link set lo up; done
sudo ip -n a1 link add eth1 type veth peer name eth1 netns b1
sudo ip -n a1 link add eth2 type veth peer name eth2 netns b1
sudo ip -n a1 link add eth0 type veth peer name eth0 netns ha
sudo ip -n b1 link add eth0 type veth peer name eth0 netns hb
sudo ip -n a1 link add lan2 type dummy
sudo ip -n a1 addr add 10.99.1.1/30 dev eth1
sudo ip -n b1 addr add 10.99.1.2/30 dev eth1
sudo ip -n a1 addr add 10.99.2.1/30 dev eth2
sudo ip -n b1 addr add 10.99.2.2/30 dev eth2
sudo ip -n a1 addr add 10.10.1.1/24 dev eth0
sudo ip -n ha addr add 10.10.1.10/24 dev eth0
sudo ip -n a1 addr add 10.10.2.1/24 dev lan2
sudo ip -n b1 addr add 10.20.1.1/24 dev eth0
sudo ip -n hb addr add 10.20.1.10/24 dev eth0
for d in eth1 eth2 eth0 lan2; do sudo ip -n a1 link set $d up; done
for d in eth1 eth2 eth0; do sudo ip -n b1 link set $d up; done
sudo ip -n ha link set eth0 up
sudo ip -n hb link set eth0 up
sudo ip -n ha route add default via 10.10.1.1
sudo ip -n hb route add default via 10.20.1.1
sudo ip netns exec a1 sysctl -qw net.ipv4.ip_forward=1
sudo ip netns exec b1 sysctl -qw net.ipv4.ip_forward=1FRR as on Day 10, this time with bgpd instead of
ospfd. The drop-in for frr@ has been in place
since Day 10:
# on netz
for r in a1 b1; do
sudo mkdir -p /etc/frr/$r
sudo sed 's/^bgpd=no/bgpd=yes/' /etc/frr/daemons | sudo tee /etc/frr/$r/daemons >/dev/null
sudo touch /etc/frr/$r/frr.conf /etc/frr/$r/vtysh.conf
sudo chown -R frr:frr /etc/frr/$r
sudo systemctl start frr@$r
done
systemctl is-active frr@a1 frr@b1
sudo ip netns exec ha ping -c1 -W1 10.20.1.10 | grep FromExpected:
active
active
From 10.10.1.1 icmp_seq=1 Destination Net Unreachable
Save your progress? Sign up for free
Drill 2: The First Session, and Why Nothing Happens
A BGP session over link 1. neighbor … remote-as names
the address and the AS number of the other side, network
says which of its own networks BGP should announce. For that, the
network must be in the routing table exactly as written:
# on netz
sudo vtysh -N a1 -c 'configure terminal' -c 'router bgp 65001' -c 'bgp router-id 10.99.1.1' -c 'neighbor 10.99.1.2 remote-as 65002' -c 'address-family ipv4 unicast' -c 'network 10.10.1.0/24' -c 'network 10.10.2.0/24' -c 'end' -c 'write memory' >/dev/null
sudo vtysh -N b1 -c 'configure terminal' -c 'router bgp 65002' -c 'bgp router-id 10.99.1.2' -c 'neighbor 10.99.1.1 remote-as 65001' -c 'address-family ipv4 unicast' -c 'network 10.20.1.0/24' -c 'end' -c 'write memory' >/dev/null
sleep 8
sudo vtysh -N a1 -c 'show bgp ipv4 unicast summary'
sudo vtysh -N a1 -c 'show bgp ipv4 unicast' | sed -n '/Network/,$p'Expected:
BGP router identifier 10.99.1.1, local AS number 65001 VRF default vrf-id 0
BGP table version 2
RIB entries 2, using 320 bytes of memory
Peers 1, using 30 KiB of memory
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc
10.99.1.2 4 65002 3 3 2 0 0 00:00:08 (Policy) (Policy) N/A
Total number of neighbors 1
Network Next Hop Metric LocPrf Weight Path
*> 10.10.1.0/24 0.0.0.0 0 32768 i
*> 10.10.2.0/24 0.0.0.0 0 32768 i
Displayed 2 routes and 2 total paths
The session has been up for 8 seconds (Up/Down shows a
time instead of a state such as Active or
Connect). But (Policy) instead of a number:
nothing is sent and nothing is accepted. This is intentional. Since RFC
8212, sessions to foreign AS (eBGP) follow the rule: no filter, no
routes. Too many outages on the internet were caused by routers that
passed on everything unfiltered. FRR complies.
Save your progress? Sign up for free
Drill 3: Filters with prefix-list and route-map
A prefix-list describes networks:
10.10.0.0/16 le 24 means “everything within 10.10.0.0/16
with a prefix length up to 24,” so 10.10.1.0/24 and
10.10.2.0/24, but not 10.10.1.128/25 and not
0.0.0.0/0. A route-map uses it as a
condition. Anything that does not match a permit line is
discarded.
a1 sends only networks of site A and accepts only
networks of site B:
# on netz
sudo vtysh -N a1 -c 'configure terminal' -c 'ip prefix-list A-NETZE seq 10 permit 10.10.0.0/16 le 24' -c 'ip prefix-list B-NETZE seq 10 permit 10.20.0.0/16 le 24' -c 'route-map NACH-B permit 10' -c 'match ip address prefix-list A-NETZE' -c 'exit' -c 'route-map VON-B permit 10' -c 'match ip address prefix-list B-NETZE' -c 'exit' -c 'router bgp 65001' -c 'address-family ipv4 unicast' -c 'neighbor 10.99.1.2 route-map VON-B in' -c 'neighbor 10.99.1.2 route-map NACH-B out' -c 'end' -c 'write memory' >/dev/null
sudo vtysh -N b1 -c 'configure terminal' -c 'ip prefix-list B-NETZE seq 10 permit 10.20.0.0/16 le 24' -c 'ip prefix-list A-NETZE seq 10 permit 10.10.0.0/16 le 24' -c 'route-map NACH-A permit 10' -c 'match ip address prefix-list B-NETZE' -c 'exit' -c 'route-map VON-A permit 10' -c 'match ip address prefix-list A-NETZE' -c 'exit' -c 'router bgp 65002' -c 'address-family ipv4 unicast' -c 'neighbor 10.99.1.1 route-map VON-A in' -c 'neighbor 10.99.1.1 route-map NACH-A out' -c 'end' -c 'write memory' >/dev/null
sleep 5
sudo vtysh -N a1 -c 'show bgp ipv4 unicast summary' | grep -A1 Neighbor
sudo vtysh -N a1 -c 'show bgp ipv4 unicast' | sed -n '/Network/,$p'Expected:
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc
10.99.1.2 4 65002 14 15 3 0 0 00:00:26 1 2 N/A
Network Next Hop Metric LocPrf Weight Path
*> 10.10.1.0/24 0.0.0.0 0 32768 i
*> 10.10.2.0/24 0.0.0.0 0 32768 i
*> 10.20.1.0/24 10.99.1.2 0 0 65002 i
Displayed 3 routes and 3 total paths
One network received, two sent. 10.20.1.0/24 has the AS
path 65002 and b1 as the next router. The
local networks have Next Hop 0.0.0.0 and
Weight 32768: local networks always win. On b1
the routes end up in the kernel:
# on netz
sudo vtysh -N b1 -c 'show ip route bgp' | sed -n '/IPv4 unicast/,$p'
sudo ip -n b1 route show proto bgp
sudo ip netns exec ha ping -c2 -q 10.20.1.10 | grep receivedExpected:
IPv4 unicast VRF default:
B>* 10.10.1.0/24 [20/0] via 10.99.1.1, eth1, weight 1, 00:00:05
B>* 10.10.2.0/24 [20/0] via 10.99.1.1, eth1, weight 1, 00:00:05
10.10.1.0/24 nhid 14 via 10.99.1.1 dev eth1 metric 20
10.10.2.0/24 nhid 14 via 10.99.1.1 dev eth1 metric 20
2 packets transmitted, 2 received, 0% packet loss, time 1041ms
[20/0]: the administrative distance of eBGP is 20, lower
than OSPF at 110. If a router knows the same network from both
protocols, BGP wins.
Save your progress? Sign up for free
Drill 4: The Second Link
A second session over link 2, with the same filters:
# on netz
sudo vtysh -N a1 -c 'configure terminal' -c 'router bgp 65001' -c 'neighbor 10.99.2.2 remote-as 65002' -c 'address-family ipv4 unicast' -c 'neighbor 10.99.2.2 route-map VON-B in' -c 'neighbor 10.99.2.2 route-map NACH-B out' -c 'end' -c 'write memory' >/dev/null
sudo vtysh -N b1 -c 'configure terminal' -c 'router bgp 65002' -c 'neighbor 10.99.2.1 remote-as 65001' -c 'address-family ipv4 unicast' -c 'neighbor 10.99.2.1 route-map VON-A in' -c 'neighbor 10.99.2.1 route-map NACH-A out' -c 'end' -c 'write memory' >/dev/null
sleep 8
sudo vtysh -N a1 -c 'show bgp ipv4 unicast summary' | sed -n '/^Neighbor/,/^$/p'
sudo vtysh -N a1 -c 'show bgp ipv4 unicast 10.20.1.0/24'Expected:
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc
10.99.1.2 4 65002 15 15 4 0 0 00:00:45 1 2 N/A
10.99.2.2 4 65002 4 4 4 0 0 00:00:07 1 2 N/A
BGP routing table entry for 10.20.1.0/24, version 4
Paths: (2 available, best #1, table default)
Not advertised to any peer
65002
10.99.1.2 from 10.99.1.2 (10.99.1.2)
Origin IGP, metric 0, valid, external, multipath, best (Older Path)
Last update: Tue Nov 24 00:56:17 2026
65002
10.99.2.2 from 10.99.2.2 (10.99.1.2)
Origin IGP, metric 0, valid, external, multipath
Last update: Tue Nov 24 00:56:30 2026
Two paths, equally good in everything that counts. BGP still picks
one, here by (Older Path): the path that has been stable
longer wins. That is the second-to-last item on a long list. The most
important ones, in this order:
| Rank | Criterion | Who wins |
|---|---|---|
| 1 | Weight (local only in FRR/Cisco) | higher |
| 2 | Local Preference | higher, applies in the whole local AS |
| 3 | locally originated | own networks |
| 4 | AS path | shorter |
| 5 | Origin | i before e before ? |
| 6 | MED | lower, a request from the neighbor |
| 7 | eBGP before iBGP | external |
| … | older path, lower router ID | tie-breaker |
That link 1 happens to win because it was there first is not a plan. After a restart it could be the other one.
Save your progress? Sign up for free
Drill 5: Defining Primary and Backup Paths
Two directions, two tools, both in your own router
a1:
- Outbound traffic from A: paths coming in over link 2 get a lower Local Preference (50 instead of 100). Rank 2, so stronger than everything after it.
- Inbound traffic to A: what A announces over link 2
gets an artificially lengthened AS path (AS-path
prepending). B then sees
65001 65001 65001instead of65001over link 2 and takes the shorter path (rank 4). A cannot dictate Local Preference to the neighbor; it only applies within the local AS.
# on netz
sudo vtysh -N a1 -c 'configure terminal' -c 'route-map VON-B-RESERVE permit 10' -c 'match ip address prefix-list B-NETZE' -c 'set local-preference 50' -c 'exit' -c 'route-map NACH-B-RESERVE permit 10' -c 'match ip address prefix-list A-NETZE' -c 'set as-path prepend 65001 65001' -c 'exit' -c 'router bgp 65001' -c 'address-family ipv4 unicast' -c 'neighbor 10.99.2.2 route-map VON-B-RESERVE in' -c 'neighbor 10.99.2.2 route-map NACH-B-RESERVE out' -c 'end' -c 'write memory' >/dev/null
sudo vtysh -N a1 -c 'clear bgp ipv4 unicast 10.99.2.2 soft'
sleep 3
sudo vtysh -N a1 -c 'show bgp ipv4 unicast' | sed -n '/Network/,$p'
sudo vtysh -N b1 -c 'show bgp ipv4 unicast' | sed -n '/Network/,$p'
sudo vtysh -N b1 -c 'show bgp ipv4 unicast 10.10.1.0/24' | grep -E 'best|^ [0-9]'Expected:
Network Next Hop Metric LocPrf Weight Path
*> 10.10.1.0/24 0.0.0.0 0 32768 i
*> 10.10.2.0/24 0.0.0.0 0 32768 i
*> 10.20.1.0/24 10.99.1.2 0 0 65002 i
* 10.99.2.2 0 50 0 65002 i
Displayed 3 routes and 4 total paths
Network Next Hop Metric LocPrf Weight Path
*> 10.10.1.0/24 10.99.1.1 0 0 65001 i
* 10.99.2.1 0 0 65001 65001 65001 i
*> 10.10.2.0/24 10.99.1.1 0 0 65001 i
* 10.99.2.1 0 0 65001 65001 65001 i
*> 10.20.1.0/24 0.0.0.0 0 32768 i
Displayed 3 routes and 5 total paths
Paths: (2 available, best #1, table default)
65001
Origin IGP, metric 0, valid, external, best (AS Path)
65001 65001 65001
On a1 the path over link 2 has LocPrf 50,
on b1 the long AS path, and the reason for the decision is
now best (AS Path) instead of Older Path.
clear … soft requests the neighbor’s routes again and
resends its own, without tearing down the session. Without this command,
FRR applies changed route-maps on its own after a few seconds.
Save your progress? Sign up for free
Drill 6: Link 1 Fails
Measurement as on Day 11; the primary link goes
DOWN:
# on netz
sudo ip netns exec ha ping -i 0.01 -c 1500 -q 10.20.1.10 > /tmp/p.txt &
sleep 3; sudo ip -n a1 link set eth1 down
wait; tail -2 /tmp/p.txt
sudo vtysh -N a1 -c 'show bgp ipv4 unicast summary' | sed -n '/^Neighbor/,/^$/p'
sudo ip -n a1 route show proto bgp
sudo ip -n b1 route show proto bgpExpected:
1500 packets transmitted, 1494 received, +2 errors, 0.4% packet loss, time 16510ms
rtt min/avg/max/mdev = 0.048/0.122/1.684/0.058 ms
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc
10.99.1.2 4 65002 16 16 0 0 0 00:00:14 Active 0 N/A
10.99.2.2 4 65002 11 13 5 0 0 00:00:48 1 2 N/A
10.20.1.0/24 nhid 23 via 10.99.2.2 dev eth2 metric 20
10.10.1.0/24 nhid 19 via 10.99.2.1 dev eth2 metric 20
10.10.2.0/24 nhid 19 via 10.99.2.1 dev eth2 metric 20
Six packets, 60 milliseconds. The session over link 1 is in
Active (FRR is trying to re-establish it), and both sides
use the backup. This was so fast because the failure was loud: FRR
terminates an eBGP session immediately when its interface goes down.
With a silent failure, the BGP timers apply:
# on netz
sudo vtysh -N a1 -c 'show bgp neighbors 10.99.2.2' | grep -E 'Hold time|keepalive'Expected:
Hold time is 180 seconds, keepalive interval is 60 seconds
Configured hold time is 180 seconds, keepalive interval is 60 seconds
Three minutes. As with OSPF, BFD helps:
neighbor 10.99.2.2 bfd with a profile as on Day 11, on both
sides. Link 1 back up:
# on netz
sudo ip -n a1 link set eth1 up
sleep 10
sudo ip -n a1 route show proto bgpExpected:
10.20.1.0/24 nhid 18 via 10.99.1.2 dev eth1 metric 20
Save your progress? Sign up for free
Exercise: Speed drills
- How many networks has
a1accepted from10.99.2.2? Just the number. Target time: 30 s - On
a1, show the path to10.20.1.0/24that has Local Preference 50. Target time: 30 s - Which AS paths does
b1see for10.10.2.0/24? Target time: 30 s
Solution
# on netz
sudo vtysh -N a1 -c 'show bgp ipv4 unicast summary' | awk '$1 == "10.99.2.2" {print $10}'
sudo vtysh -N a1 -c 'show bgp ipv4 unicast 10.20.1.0/24' | grep -B2 'localpref 50' | head -3
sudo vtysh -N b1 -c 'show bgp ipv4 unicast 10.10.2.0/24' | grep -E '^ 65001'Expected:
1
65002
10.99.2.2 from 10.99.2.2 (10.99.1.2)
Origin IGP, metric 0, localpref 50, valid, external
65001
65001 65001 65001
Save your progress? Sign up for free
Challenge
The examiner plays a colleague at site B who is “trying something out”: he announces a default route and the LAN of site A, loosening his outbound filter to do so:
# on netz
sudo vtysh -N b1 -c 'configure terminal' -c 'ip route 10.10.1.0/24 blackhole' -c 'ip route 0.0.0.0/0 blackhole' -c 'ip prefix-list B-NETZE seq 20 permit 0.0.0.0/0 le 32' -c 'router bgp 65002' -c 'address-family ipv4 unicast' -c 'network 10.10.1.0/24' -c 'network 0.0.0.0/0' -c 'end' >/dev/null
clearHad a1 accepted this, its own LAN would have been moved
to B from A’s point of view, and all unknown traffic would have been
sent into a black hole. Check whether a1 is still working
correctly, and prove that b1 actually sent more than
a1 takes over.
Hint: The summary only counts what got through the
filter. To see what arrived before it, a1 has to remember
the unfiltered announcements.
Solution
# on netz
sudo vtysh -N a1 -c 'show bgp ipv4 unicast summary' | sed -n '/^Neighbor/,/^$/p'
sudo ip netns exec ha ping -c1 -W1 10.20.1.10 | grep -o '1 received'Expected:
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd PfxSnt Desc
10.99.1.2 4 65002 23 20 6 0 0 00:00:28 1 2 N/A
10.99.2.2 4 65002 15 14 6 0 0 00:01:16 1 2 N/A
1 received
From the outside nothing is visible: still one network per session,
everything works. That is the filter at work. To make the attempt
visible, a1 uses soft-reconfiguration inbound
to keep a copy of all received announcements, before the filter:
# on netz
sudo vtysh -N a1 -c 'configure terminal' -c 'router bgp 65001' -c 'address-family ipv4 unicast' -c 'neighbor 10.99.1.2 soft-reconfiguration inbound' -c 'end' >/dev/null
sleep 2
sudo vtysh -N a1 -c 'show bgp ipv4 unicast neighbors 10.99.1.2 received-routes' | sed -n '/Network/,$p'
sudo vtysh -N a1 -c 'show bgp ipv4 unicast neighbors 10.99.1.2 routes' | sed -n '/Network/,$p'Expected:
Network Next Hop Metric LocPrf Weight Path
*> 0.0.0.0/0 10.99.1.2 0 0 65002 i
*> 10.10.1.0/24 10.99.1.2 0 0 65002 i
*> 10.10.2.0/24 10.99.1.2 0 65002 65001 i
*> 10.20.1.0/24 10.99.1.2 0 0 65002 i
Total number of prefixes 4 (3 filtered)
Network Next Hop Metric LocPrf Weight Path
*> 10.20.1.0/24 10.99.1.2 0 0 65002 i
Displayed 1 routes and 4 total paths
Four announcements, three filtered: the default route, the hijacked
LAN, and even 10.10.2.0/24, which b1 sends
back to A with its loosened filter (AS path 65002 65001).
BGP would have discarded this network even without a filter, because its
own AS number is in the path: the loop protection. The other two are
stopped only by the prefix-list B-NETZE of
a1.
The colleague cleans up:
# on netz
sudo vtysh -N b1 -c 'configure terminal' -c 'router bgp 65002' -c 'address-family ipv4 unicast' -c 'no network 10.10.1.0/24' -c 'no network 0.0.0.0/0' -c 'exit' -c 'exit' -c 'no ip prefix-list B-NETZE seq 20 permit 0.0.0.0/0 le 32' -c 'no ip route 10.10.1.0/24 blackhole' -c 'no ip route 0.0.0.0/0 blackhole' -c 'end' >/dev/null
sleep 8
sudo vtysh -N a1 -c 'show bgp ipv4 unicast neighbors 10.99.1.2 received-routes' | sed -n '/Network/,$p'Expected:
Network Next Hop Metric LocPrf Weight Path
*> 10.20.1.0/24 10.99.1.2 0 0 65002 i
Total number of prefixes 1, total number of paths 0
soft-reconfiguration inbound costs memory because every
announcement is held twice. On a session with the full internet routing
table (over a million networks), you think twice about it.
Save your progress? Sign up for free
Checkpoint
# on netz
sudo vtysh -N a1 -c 'show bgp ipv4 unicast summary' | grep -c '^10.99'
sudo ip -n a1 route show proto bgpExpected:
2
10.20.1.0/24 nhid 18 via 10.99.1.2 dev eth1 metric 20
# on netz
sudo vtysh -N b1 -c 'show running-config' | grep -c 'network 0.0.0.0/0'
sudo ip netns exec ha ping -c1 -W1 10.20.1.10 | grep -o '1 received'Expected:
0
1 received
Clean-up
# on netz
sudo systemctl stop frr@a1 frr@b1
sudo rm -rf /etc/frr/a1 /etc/frr/b1
sudo ip netns del a1
sudo ip netns del b1
sudo ip netns del ha
sudo ip netns del hb
rm -f /tmp/p.txt
ip netns list | wc -l
pgrep -c -x bgpdExpected:
0
0
Practice note
- No BGP session without filters in both directions.
Inbound only what the neighbor is allowed to have (its networks, with a
maximum length), outbound only your own. This includes
neighbor … maximum-prefix, which terminates a session if the neighbor suddenly sends thousands of networks. - Steer with Local Preference for your own traffic, with AS-path prepending for traffic to you. Prepending is a request, not an instruction: if the neighbor has set a higher Local Preference for the other path, it ignores your long path.
- “Older Path” as the reason for the decision is a warning sign. It means nothing is configured and chance decides.
- BFD for BGP, otherwise a silent failure costs the
hold time of three minutes. For troubleshooting filters, temporarily
enable
soft-reconfiguration inboundand comparereceived-routeswithroutes.