Setting Up BGP Routing with Pathvector and BIRD on Ubuntu

Aman Ullah Juman
3 min readMay 29, 2024

--

Configuring Border Gateway Protocol (BGP) routing for your virtual private server (VPS) ensures efficient and reliable routing of network traffic. This guide will walk you through the process of setting up BGP routing using Pathvector and BIRD on an Ubuntu 22.04 server. We will use placeholder values for IP addresses, prefixes, and ASNs, which you can replace with your specific details.

Prerequisites

Before we begin, ensure you have the following:

  • A VPS running Ubuntu 22.04
  • Basic knowledge of Linux command-line operations
  • Access to your VPS as a root user or a user with sudo privileges
  • Your Autonomous System Number (ASN), IPv4, and IPv6 prefixes

Step 1: Install Pathvector and BIRD

First, we need to install Pathvector, BIRD, and bgpq4. Use the following commands to set up the repository and install the necessary packages:

curl https://repo.pathvector.io/pgp.asc > /usr/share/keyrings/pathvector.asc
echo "deb [signed-by=/usr/share/keyrings/pathvector.asc] https://repo.pathvector.io/apt/ stable main" > /etc/apt/sources.list.d/pathvector.list
apt update && apt install -y pathvector bird2 bgpq4

Once the installation is complete, enable and start the BIRD service:

Step 2: Configure Pathvector

Create and edit the Pathvector configuration file to set up your BGP parameters. Replace the placeholder values with your actual ASN, prefixes, and other relevant details:

asn: <YOUR_ASN>
router-id: <YOUR_ROUTER_ID>
bgpq-args: -S RIPE,APNIC,ARIN,LACNIC,AFRINIC
irr-server: rr.ntt.net
rtr-server: rtr.rpki.cloudflare.com:8282
accept-default: true
default-route: false
keep-filtered: true

kernel:
export: false

prefixes:
- <YOUR_IPV4_PREFIX>/24
- <YOUR_IPV6_PREFIX>/48

templates:
upstream:
allow-local-as: true
announce: ["<YOUR_ASN>:0:15"]
remove-all-communities: <YOUR_ASN>
local-pref: 80
add-on-import: ["<YOUR_ASN>:0:12"]

routeserver:
filter-transit-asns: true
auto-import-limits: true
enforce-peer-nexthop: false
enforce-first-as: false
announce: ["<YOUR_ASN>:0:15"]
remove-all-communities: <YOUR_ASN>
local-pref: 90
add-on-import: ["<YOUR_ASN>:0:13"]

peer:
filter-irr: true
filter-transit-asns: true
auto-import-limits: true
auto-as-set: true
announce: ["<YOUR_ASN>:0:15"]
remove-all-communities: <YOUR_ASN>
local-pref: 100
add-on-import: ["<YOUR_ASN>:0:14"]

downstream:
filter-irr: true
allow-blackhole-community: true
filter-transit-asns: true
auto-import-limits: true
auto-as-set: true
announce: ["<YOUR_ASN>:0:15"]
announce-default: true
remove-all-communities: <YOUR_ASN>
local-pref: 200
add-on-import: ["<YOUR_ASN>:0:15"]

peers:
ExamplePeer:
asn: <PEER_ASN>
multihop: true
template: upstream
enforce-peer-nexthop: false
enforce-first-as: false
neighbors:
- <PEER_IPV4_ADDRESS>
- <PEER_IPV6_ADDRESS>
password: <BGP_PASSWORD>

Step 3: Generate BIRD Configuration with Pathvector

Run the following command to generate the BIRD configuration using Pathvector:

pathvector generate

Step 4: Verify and Restart BIRD Service

After generating the configuration, restart the BIRD service to apply the changes:

bird -p -c /etc/bird/bird.conf
sudo systemctl restart bird

Verify BGP Route Announcements

Check the routes being advertised:

birdc show route export ExamplePeer_v4
birdc show route export ExamplePeer_v6

Once the installation and configuration is complete, enable the BIRD service:

systemctl enable bird

Step 5: Set Up the Dummy Interface (Optional)

A dummy interface is necessary to assign IP addresses that don’t exist on the physical interface. This setup allows us to configure IP addresses from our prefixes on a loopback-like interface.

Create the Dummy Interface Script

Create a script to set up the dummy interface and ensure it runs at boot:

sudo nano /usr/local/bin/setup-dummy-interface.sh

Add the following content to the script, replacing <YOUR_IPV4_INTERFACE_IP>, <YOUR_IPV6_INTERFACE_IP>, and other placeholders with your specific details:

#!/bin/bash
ip link add dummy0 type dummy
ip addr add <YOUR_IPV4_INTERFACE_IP>/24 dev dummy0
ip addr add <YOUR_IPV6_INTERFACE_IP>/64 dev dummy0
ip link set dummy0 up

Make the script executable:

sudo chmod +x /usr/local/bin/setup-dummy-interface.sh

Create a Systemd Service for the Script

Create a systemd service to run the script at boot:

sudo nano /etc/systemd/system/dummy-interface.service

Add the following content:

[Unit]
Description=Setup Dummy Interface
After=network.target

[Service]
ExecStart=/usr/local/bin/setup-dummy-interface.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl enable dummy-interface.service
sudo systemctl start dummy-interface.service

Step 6: Verify Connectivity

To ensure that your BGP setup is functioning correctly, perform the following checks:

Ping Test

Verify connectivity using the ping command:

ping -I <YOUR_IPV4_INTERFACE_IP> 8.8.8.8
ping6 -I <YOUR_IPV6_INTERFACE_IP> 2001:4860:4860::8888

Curl Test

Check your public IP address using curl:

curl --interface <YOUR_IPV4_INTERFACE_IP> -4 ifconfig.me
curl --interface <YOUR_IPV6_INTERFACE_IP> -6 ifconfig.me

Traceroute Test

Ensure proper routing with traceroute:

traceroute -i <YOUR_IPV4_INTERFACE_IP> google.com
traceroute6 -i <YOUR_IPV6_INTERFACE_IP> google.com

Conclusion

Setting up BGP routing on your VPS using Pathvector and BIRD ensures efficient network traffic management. Following this guide, you can configure your BGP parameters and verify the setup to ensure everything works correctly. Replace placeholder values with your actual network details to get started.

For more detailed information and troubleshooting, refer to the Pathvector Documentation and BIRD Documentation.

--

--