.\" $OpenBSD: carp.4,v 1.11 2004/07/26 09:20:14 jmc Exp $ .\" .\" Copyright (c) 2003, Ryan McBride. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .Dd October 16, 2003 .Dt CARP 4 .Os .Sh NAME .Nm carp .Nd Common Address Redundancy Protocol .Sh SYNOPSIS .Cd "pseudo-device carp" Op Ar count .Sh DESCRIPTION The .Nm interface is a pseudo-device which implements and controls the CARP protocol. .Nm allows multiple hosts on the same local network to share a set of IP addresses. Its primary purpose is to ensure that these addresses are always available, but in some configurations .Nm can also provide load balancing functionality. .Pp A .Nm interface can be created at runtime using the .Ic ifconfig carpN create command or by setting up a .Xr hostname.if 5 configuration file for .Xr netstart 8 . .Pp To use .Nm , the administrator needs to configure at minimum a common virtual host ID and virtual host IP address on each machine which is to take part in the virtual group. Additional parameters can also be set on a per-interface basis: .Ar advbase and .Ar advskew , which are used to control how frequently the host sends advertisements when it is the master for a virtual host, and .Ar pass which is used to authenticate carp advertisements. These configurations can be done using .Xr ifconfig 8 , or through the .Dv SIOCSVH ioctl. .Pp Additionally, there are a number of global parameters which can be set using .Xr sysctl 8 . .Sh EXAMPLES In order to set up an ARP balanced virtual host, it is necessary to configure one virtual host for each physical host which would respond to ARP requests and thus handle the traffic. In the following example, 2 hosts are configured to provide balancing and failover for the IP address 192.168.1.10. .Pp First the .Nm interfaces on Host A are configured. The .Ar advskew of 100 on the second virtual host means that its advertisements will be sent out slightly less frequently. .Bd -literal -offset indent # ifconfig carp0 create # ifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.10 \e 255.255.255.0 # ifconfig carp1 create # ifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat \e 192.168.1.10 255.255.255.0 .Ed .Pp The configuration for host B is identical, except the skew is on virtual host 1 rather than virtual host 2. .Bd -literal -offset indent # ifconfig carp0 create # ifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat \e 192.168.1.10 255.255.255.0 # ifconfig carp1 create # ifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.1.10 \e 255.255.255.0 .Ed .Pp Finally, the ARP balancing feature must be enabled on both hosts: .Pp .Dl # sysctl net.inet.carp.arpbalance=1 .Pp When the hosts receive an ARP request for 192.168.1.10, they both select one of the virtual hosts based on the source IP address in the request. The host which is master of that virtual host will reply to the request, the other will ignore it. .Pp Because the host which advertises most often will tend to be the master, the result of this is that Host A will tend to be the master for the virtual host with ID 1, while Host B will tend to be the master for the virtual host with ID 2, and therefore arp requests and subsequent IP traffic are balanced across the two hosts. If one of the hosts fails, the other will take over the virtual MAC address, and begin answering ARP requests on its behalf. .Pp Note: ARP balancing only works on the local network segment. Connections which cross a router to arrive on the local network segment will all appear to come from that router and be balanced to the same host. .Sh SEE ALSO .Xr sysctl 3 , .Xr inet 4 , .Xr hostname.if 5 , .Xr ifconfig 8 , .Xr netstart 8 , .Xr sysctl 8 .Sh HISTORY The .Nm device first appeared in .Ox 3.5 .