DEV Community

IPYE
IPYE

Posted on

GoBGP: Announce and Withdraw a Free /48 from Code

Disclosure up front: I run IPYE, a company that leases IP space. Most of this article is practical how-to; IPYE appears where a free /48, LOA, or ROA helps you try the work, with a short call to action at the end.

Most BGP daemons are configured through files and reloaded. GoBGP takes a different approach: a small daemon with a gRPC API and a CLI that talks to it, so routes can be added and removed at runtime by scripts, health checks or a controller. It is a good fit for hosts that only need to announce, such as an anycast service node or a scrubbing setup, and for experiments where you want to drive BGP from code. This article runs GoBGP for a free IPv6 /48 from IPYE, with 2001:db8:100::/48, AS64496, and an upstream AS64511 at 2001:db8:0:1::1.

What GoBGP does and does not do

GoBGP speaks BGP and keeps its own RIB. By default it does not install learned routes into the Linux kernel. That makes it lightweight on a host that only originates routes, but it also means it is not a drop-in router. If you need learned routes in the kernel, it can integrate with FRR's zebra, and many people simply run FRR or BIRD for that role and keep GoBGP for announcements.

Minimal configuration

# /etc/gobgpd.toml
[global.config]
  as = 64496
  router-id = "192.0.2.10"

[[neighbors]]
  [neighbors.config]
    neighbor-address = "2001:db8:0:1::1"
    peer-as = 64511
    description = "upstream"
  [[neighbors.afi-safis]]
    [neighbors.afi-safis.config]
      afi-safi-name = "ipv6-unicast"
Enter fullscreen mode Exit fullscreen mode

Run it under systemd:

[Service]
ExecStart=/usr/local/bin/gobgpd -f /etc/gobgpd.toml
Restart=always
Enter fullscreen mode Exit fullscreen mode

The gRPC API listens on localhost port 50051 by default. Keep it there, or protect it with a firewall. Anyone who can reach the API can change your announcements.

Announce from the CLI

gobgp neighbor
gobgp global rib -a ipv6 add 2001:db8:100::/48
gobgp neighbor 2001:db8:0:1::1 adj-out -a ipv6
Enter fullscreen mode Exit fullscreen mode

adj-out shows exactly what is sent to the neighbour. Withdraw with:

gobgp global rib -a ipv6 del 2001:db8:100::/48
Enter fullscreen mode Exit fullscreen mode

Routes added through the CLI live in memory. If the daemon restarts, they are gone until something adds them again. That is a feature for health-checked announcements, since a dead controller stops announcing, but you need to plan for it. For a static origin, add the route from an ExecStartPost line or from your controller's start-up logic.

Export policy

With one upstream and nothing else, GoBGP only has your own route to send. Once you add a second neighbour, it will by default pass routes learned from one to the other. Define an export policy that only allows your prefix:

[[defined-sets.prefix-sets]]
  prefix-set-name = "own"
  [[defined-sets.prefix-sets.prefix-list]]
    ip-prefix = "2001:db8:100::/48"

[[policy-definitions]]
  name = "export-own"
  [[policy-definitions.statements]]
    [policy-definitions.statements.conditions.match-prefix-set]
      prefix-set = "own"
    [policy-definitions.statements.actions]
      route-disposition = "accept-route"

[global.apply-policy.config]
  export-policy-list = ["export-own"]
  default-export-policy = "reject-route"
Enter fullscreen mode Exit fullscreen mode

default-export-policy = "reject-route" turns this into an allow-list. Anything not matching own stays home.

Drive it from a health check

The point of an API-first daemon is automation. A small loop that announces only while a local service answers is a common pattern:

#!/bin/sh
while true; do
  if curl -6 -fsS -m 2 http://[2001:db8:100:1::10]/health >/dev/null; then
    gobgp global rib -a ipv6 add 2001:db8:100::/48 >/dev/null 2>&1
  else
    gobgp global rib -a ipv6 del 2001:db8:100::/48 >/dev/null 2>&1
  fi
  sleep 5
done
Enter fullscreen mode Exit fullscreen mode

Adding an existing route again is harmless, so the loop does not need to track state. For anything beyond a lab, write the controller against the gRPC API in Go or Python. You get proper error handling, and you can watch the RIB for changes instead of polling.

Be careful with the whole /48 in this pattern. If the health check fails on your only site, the prefix disappears from the Internet entirely. Withdrawal-on-failure makes most sense when another site announces the same prefix, or when you announce a more-specific that only some networks will accept.

Firewall and verification

Allow TCP 179 from the neighbour and keep ICMPv6 open on the uplink. From outside, confirm with a traceroute to an address that is actually configured on the host, such as 2001:db8:100::1 on a dummy interface.

ip link add free48 type dummy
ip link set free48 up
ip -6 addr add 2001:db8:100::1/128 dev free48
Enter fullscreen mode Exit fullscreen mode

ROA and LOA

Health-checked announcements still need a valid origin. Because the free /48 sits on IPYE's ARIN or APNIC accounts, the ROA is created automatically for the ASN you choose. For the upstream's filter, get the Letter of Authorization from the IPYE portal.

Do this next

Get your free /48, run GoBGP with a default-reject export policy, and test an add and a delete while you watch adj-out from a second terminal. Questions: ipye@turnel.com.

About IPYE

IPYE (https://ipye.com) leases IPv4, IPv6 and ASN space with instant setup. Your first IPv6 /48 is free for the first year, a real allocation you can announce on your own ASN, with a LOA from the portal and the ROA created automatically. ASN and region changes apply automatically. IPv4 /24 to /22 leases include LOA, ROA and per-/24 rDNS; WHOIS is editable on IPv6 /44 and larger. Locations: Los Angeles, New York, Ashburn, Salt Lake City, London, Amsterdam, Frankfurt. Claim your free /48: https://my.ipye.com/products/ipv6-rental. Questions: ipye@turnel.com.

Disclosure: I run IPYE

Top comments (0)