IPv4 Anycast with Linux and Quagga
Many projects provide routing protocol dæmons for Linux, any number of which would be usable for this scenario. For this article, I use Quagga, which is a fork of GNU Zebra. Quagga is available both on the install media and from the standard package repositories of pretty much every enterprise-oriented Linux distribution.
For the following examples, I also use a network populated with Cisco routers, running OSPF version 2, for IPv4. Quagga also supports BGP, RIP, RIPng and OSPFv3. The remainder of this article assumes at least a basic familiarity with OSPF theory and configuration. (See Resources for links to basic primers.) Cisco also publishes a ton of very good reference material (again, see Resources). I cover the required configuration on the router side, but not in extensive detail.
Now, let's get down to the good stuff: setting up Quagga on Linux. To begin, I describe how to install Quagga, set up a loopback alias to hold the anycast IP address and configure Quagga to talk to your local routers. Then, I go over a few optional configuration extras.
First, install Quagga. For example, on Red Hat Enterprise Linux (RHEL), run yum install quagga. Substitute the appropriate package-management command for your distribution, as needed.
Next, create a loopback interface alias on the system. Configure the anycast IP address on this loopback interface. Using a loopback interface alias instead of a physical interface alias allows you to do a number of cool things. You could segment your service traffic from your administrative traffic. You could add some redundancy by responding to the anycast address on two physical interfaces, each attached to a different router or switch (although I won't go into that kind of configuration here). You also could take down the anycast interface (and, therefore, remove that interface from the anycast scheme) without affecting your ability to administer the system remotely. On RHEL, the interface configuration files are located in /etc/sysconfig/networking-scripts/. Create a file in that directory named ifcfg-lo:0 with the following contents:
# cat /etc/sysconfig/networking-scripts/ifcfg-lo:0 DEVICE=lo:0 IPADDR=10.0.0.1 NETMASK=255.255.255.255 BOOTPROTO=none ONBOOT=yes
That file's format is fairly self-explanatory. You can control the lo:0 interface with your normal interface control commands (ifup, ifdown, ifconfig and so on).
Some versions of Fedora use NetworkManager to control eth0 by default. This may cause strange things to happen when you try to bring up a loopback alias. If that happens to you, add the line NM_CONTROLLED=no to /etc/sysconfig/networking-scripts/ifcfg-eth0, and restart your network. At this point, you should be able to bring up your new interface with ifup lo:0.
Now, you need to configure Quagga. By default, the Quagga configuration files are in /etc/quagga and /etc/sysconfig/quagga. There are a number of example configuration files in /etc/quagga: one for each routing protocol that Quagga supports; one for zebra, the main process; and one for the vtysh configuration. We primarily are interested in the ospfd.config and zebra.config files. The syntax in those files is similar to the standard Cisco configuration syntax, but with important differences. Also note that, by default, all routing processes bind to a dæmon-specific port on 127.0.0.1. If you configure a password for that routing process and Telnet to that port, you can monitor and configure the process on the fly using the same Cisco-like syntax. In these files, ! is the comment character:
# cat zebra.conf hostname Endpoint1 ! interface eth0 ip address 10.0.1.2/24 ! interface lo:0 ip address 10.0.0.1/32
The above file is pretty quick and easy. It contains the IP addresses and netmasks of the physical adapters and the loopback adapter that has the anycast address. This file is much more complex:
# cat ospfd.conf hostname Endpoint1 ! interface eth0 ip ospf authentication message-digest ip ospf message-digest-key 1 md5 foobar ip ospf priority 0 ! router ospf log-adjacency-changes ospf router-id 10.0.1.2 area 10.0.1.2 authentication message-digest area 10.0.1.2 nssa network 10.0.1.0/24 area 10.0.1.2 redistribute connected metric-type 1 distribute-list ANYCAST out connected ! access-list ANYCAST permit 10.0.0.1/32
Let's go over the above section by section, starting with the following:
interface eth0 ip ospf authentication message-digest ip ospf message-digest-key 1 md5 foobar
The first thing in the file is the OSPF MD5 authentication configuration. Always configure MD5 authentication on your OSPF sessions. Replace foobar with the appropriate key for your environment.
Next, we have:
ip ospf priority 0
Also set the OSPF priority to 0, which prevents the server from being elected as the Designated Router on that link.
Next come the router configuration directives:
router ospf log-adjacency-changes
log-adjacency-changes is a great configuration directive that gives you more details when there is a change in neighbor relationships between your server and any other OSPF-speaking device.
ospf router-id 10.0.1.2
Here the router ID is set to the server's service address. Router IDs must be unique within the routing domain.
We then configure this server to be in its own Not So Stubby Area (NSSA):
area 10.0.1.2 authentication message-digest area 10.0.1.2 nssa redistribute connected metric-type 1 distribute-list 5 out connected
NSSA areas are a form of stub area that limits the routes sent into the area to summary routes, but still allows external routes to come from that area. We need to allow external routes because we advertise our anycast IP address by redistributing our connected interfaces and running that through a distribute list to confine our advertised interfaces to just the anycast IP address. However, we don't want this server to have to deal with all the routes in area 0.0.0.0.
The following statement selects the interfaces that will participate in OSPF:
network 10.0.1.0/24 area 10.0.1.2
We want our eth0 interface to participate in OSPF, so we specify 10.0.1.0/24, and we put those interfaces in area 10.0.1.1.
The following line defines the access list that will allow route advertisements out:
access-list ANYCAST permit 10.0.0.1/32
Now that Quagga is configured, we need to open up the proper IP protocol number on our firewall. OSPF uses protocol number 89. The details of opening that particular protocol number will vary significantly with the firewall configuration you're using.
In general, you'll use a command like this:
# iptables -I INPUT -p 89 -j ALLOW
- diff -u: What's New in Kernel Development
- Divx# Watch The Other Woman Full HD Online Streaming Viooz
- Numerical Python
- Use Linux as a SAN Provider
- Great Scott! It's Version 13!
- NSA: Linux Journal is an "extremist forum" and its readers get flagged for extra surveillance
- Tech Tip: Really Simple HTTP Server with Python
- RSS Feeds
- Adminer—Better Than Awesome!
- Linux Systems Administrator