Building networks with FreeBSD (Part 2)

Welcome to the second part of my tutorial series. In this post we’ll see how to use the Quagga Software Suite for dynamic routing.

The dynamic routing protocols we ‘ll use are the most widely used today: RIP, OSPF and BGP.

For some details on what these protocols are used for, and how they work, you can take a look at this post.

At the end of the post you will find details for the IPv6 versions of these protocols.

Note about notation: to indicate shell commands I’ll be using $, and for quagga commands #.

Introduction to the Quagga Shell

Mode Command Run it from Prompt
Priviledged mode $ vtysh FreeBSD Shell #
Configuration mode # con t Priviledged Shell (config)#
Interface Configuration mode (config)# int <interface> Configuration Shell (config-if)#
Router Configuration mode (config)# router <router> Configuration Shell (config-router)#

To run a command that needs to be run in Priviledged mode, but through another prompt, prepend do to your command.

To exit a mode and return to the previous at any time, run exit or ex, or just hit Ctrl+Z.

To cancel a command, re-write it and prepend no.

To see all running configurations, run sh run.

Get help for command syntax with ? at any time.

You can run quagga commands from the shell directly with vtysh -c "my_command".

Save configuration:

# wr mem

Basic interface configuration

Enter interface configuration mode for em0:

(config)# int em0

Assign static address

(config-if)# ip addr

Shutdown interface:

(config-if)# shutdown

Watch for changes in interface status:

(config-if)# link-detect

Static routing with Quagga

Enable packet forwarding:

(config)# ip forwarding

Add static route to via with administrative distance 1 (optional):

(config)# ip route 1

RIP Protocol

Enable RIP and enter router configuration mode for RIP:

(config)# router rip

Enable RIP on all interfaces that belong to the network with IP address

(config-router)# net

Enable RIP on interface em0:

(config-router)# net em0

Set em0 to be a passive interface (does not send RIP updates):

(config-router)# passive-interface em0

Set RIP protocol version number (1 or 2):

(config-router)# version 1 (or 2)

Specify neighbor to unicast updates (important: RIPv2 by default RIP multicasts its updates through all associated interfaces, so this command must be combined with “passive-interface” to avoid sending simultaneously unicasts and multicasts)

(config-router)# neighbor

Change timers

(config-router)# timers basic <update> <timeout> <garbage>

See RIP status

# sh ip rip status

OSPF Protocol


Enter router configuration mode for OSPF:

(config)# router ospf

Set router ID to

(config-router)# router-id


Enable OSPF on interfaces that belong in the network and relate them to area 1 (area 0 is the backbone):

(config-router)# network area 1

Set interface em0 to be a passive interface (does not send OSPF advertisements):

(config-router)# passive-interface em0

Specify that area 1 is of type stub (has only one router):

(config-router)# area 1 stub

Specify network type (e.g. broadcast, point-to-point etc):

(config-if)# ospf network <type>


Show OSPF general information and areas:

# show ip ospf

Show OSPF information about interface em0:

# show ip ospf interface em0

Show OSPF information about neighbors of interface em0:

# show ip ospf neighbor em0

Display LSDB:

# show ip ospf database

Display information for a specific type of LSA (e.g. router, network, summary etc):

# show ip ospf database <type>

Show OSPF routing table:

# show ip ospf route

Show ABRs:

# show ip ospf border-routers

BGP Protocol


Enter router configuration mode for bgp, in AS (autonomous system) 65010

(config)# router bgp 65010


Add network to be advertised by BGP (does not activate bgp) on corresponding interfaces:

(config-router)# network

Add router with IP in list of BGP neighbors in AS 65020:

(config-router)# neighbor remote-as 65020

Set the IP address as router ID:

(config-router)# bgp router-id

Announce static/connected/rip/ospf routes respectively:

(config-router)# redistribute static/connected/rip/ospf

Aggregate network prefixes to reduce the size of BGP routing table:

(config-router)# aggregate-address


Show general info that BGP has learned:

# show ip bgp 

…or a short summary of them:

# show ip bgp summary

Show BGP path information for network

# show ip bgp

Show info for BGP neighbors:

# show ip bgp neighbors

Show info for neighbor

# show ip bgp neighbors 

Show advertised routes to neighbor

# show ip bgp neighbors advertised-routes 

Show routes that BGP learns from neighbor

# show ip bgp neighbors routes 

Applying policies

Create a filter (prefix list) of permitted (permit) or denied (deny) prefixes with name PrefixListName:

(config)# ip prefix-list PrefixListName permit/deny prefix 

Apply prefix list with name PrefixListName to neighbor to incoming (in) or outgoing (out) traffic:

(config-router)# neighbor prefix-list PrefixListName in/out 

Create a route map and define order=100 (sequence to insert to/delete from existing route-map entry):

(config)# route-map RouteMapName permit/deny 100

Apply route map in neighbor to incoming (in) or outgoing (out) traffic:

(config-router)# neighbor route-map RouteMapName in/out 


General (Shell)

To enable ipv6 on em0 and accept Router Advertisement messages:

$ sysrc ifconfig_em0_ipv6="inet6 accept_rtadv"

Assign ipv6 address fd00:1::2/64 to interface em0:

$ ifconfig em0 inet6 fd00:1::2/64

Show routing table:

$ netstat -r6

Show ndp table (Neighbor Discovery Protocol - Substitute for ARP)

$ ndp -a

Add as default gateway the host fd00:1::1 :

$ route -6 add default fd00:1::1

Routing (Quagga)

Enable daemons for ipv6:

$ service quagga stop
$ touch /usr/local/etc/quagga/ripngd.conf
$ chown quagga:quagga /usr/local/etc/quagga/ripngd.conf
$ touch /usr/local/etc/quagga/ospf6d.conf
$ chown quagga:quagga /usr/local/etc/quagga/ospf6d.conf
$ sysrc quagga_daemons="zebra ripd ripngd ospfd opdf6d bgpd"
$ service quagga start

Assign address fd00:1::1/64 to an interface:

(config-if)# ipv6 a fd00:1::1/64

Show routing table for ipv6:

# sh ipv6 route


Add static route to network fd00:2::/64 through fd00:3::2

(config)# ipv6 route fd00:2::/64 fd00:3::2



Enter router configuration mode for ripng:

(config)# router ripng

Enable RIP for ipv6 on interface em0:

(config-router)# net em0

Enter router configuration mode for BGP:

(config)# router ospf6

Specify as router ID:

(config-ospf6)# router-id

Activate ospf on interface em0 in area

(config-ospf6)# int em0 area

Enter router configuration mode for BGP declaring autonomous system (AS) 65010

(config)# router bgp 65010

Set router ID

(config-router)# bgp router-id

Disable IPv4 unicast for neighbor establishment (do this only if you use entirelly IPv6 addresses)

(config-router)# no bgp default ipv4-unicast

Declare router with address fd00:3::2 as neighbor in AS 65020:

(config-router)# neighbor fd00:3::2 remote-as 65020

Enter submenu for address family IPv6:

(config-router)# address-family ipv6

Advertise network fd00:2::/64

(config-router-af)# net fd00:1::/64

Enable neighbor relation with fd00:3::2 :

(config-router-af)# neighbor fd00:3::2 activate

I hope the series was helpful. If you have any questions, feel free to send me an email.