xref: /freebsd/share/man/man4/carp.4 (revision ceaec73d406831b1251babb61675df0a1aa54a31)
1.\"	$OpenBSD: carp.4,v 1.16 2004/12/07 23:41:35 jmc Exp $
2.\"
3.\" Copyright (c) 2003, Ryan McBride.  All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd April 7, 2005
29.Dt CARP 4
30.Os
31.Sh NAME
32.Nm carp
33.Nd Common Address Redundancy Protocol
34.Sh SYNOPSIS
35.Cd "device carp"
36.Sh DESCRIPTION
37The
38.Nm
39interface is a pseudo-device that implements and controls the
40CARP protocol.
41CARP allows multiple hosts on the same local network to share a set of IP addresses.
42Its primary purpose is to ensure that these
43addresses are always available, but in some configurations
44.Nm
45can also provide load balancing functionality.
46.Pp
47A
48.Nm
49interface can be created at runtime using the
50.Nm ifconfig Li carp Ns Ar N Cm create
51command or by configuring
52it via
53.Va cloned_interfaces
54in the
55.Pa /etc/rc.conf
56file.
57.Pp
58To use
59.Nm ,
60the administrator needs to configure at minimum a common virtual host ID and
61virtual host IP address on each machine which is to take part in the virtual
62group.
63Additional parameters can also be set on a per-interface basis:
64.Cm advbase
65and
66.Cm advskew ,
67which are used to control how frequently the host sends advertisements when it
68is the master for a virtual host, and
69.Cm pass
70which is used to authenticate
71.Nm
72advertisements.
73The
74.Cm advbase
75parameter stands for
76.Qq advertisement base .
77It is measured in seconds and specifies the base of the adverisement interval.
78The
79.Cm advskew
80parameter stands for
81.Qq advertisement skew .
82It is measured in 1/256 of seconds.
83It is added to the base advertisement interval to make one host advertise
84a bit slower that the other does.
85Both
86.Cm advbase
87and
88.Cm advskew
89are put inside CARP advertisments.
90These configurations can be done using
91.Xr ifconfig 8 ,
92or through the
93.Dv SIOCSVH
94.Xr ioctl 2 .
95.Pp
96Additionally, there are a number of global parameters which can be set using
97.Xr sysctl 8 :
98.Bl -tag -width ".Va net.inet.carp.arpbalance"
99.It Va net.inet.carp.allow
100Accept incoming
101.Nm
102packets.
103Enabled by default.
104.It Va net.inet.carp.preempt
105Allow virtual hosts to preempt each other.
106It is also used to failover
107.Nm
108interfaces as a group.
109When the option is enabled and one of the
110.Nm
111enabled physical interfaces
112goes down,
113.Cm advskew
114is changed to 240 on all
115.Nm
116interfaces.
117See also the first example.
118Disabled by default.
119.It Va net.inet.carp.log
120Value of 0 disables any logging.
121Value of 1 enables logging of bad
122.Nm
123packets.
124Values above 1 enable logging state changes of
125.Nm
126interfaces.
127Default value is 1.
128.It Va net.inet.carp.arpbalance
129Balance local traffic using ARP.
130Disabled by default.
131.El
132.Sh EXAMPLES
133For firewalls and routers with multiple interfaces, it is desirable to
134failover all of the
135.Nm
136interfaces together, when one of the physical interfaces goes down.
137This is achieved by the preempt option.
138Enable it on both host A and B:
139.Pp
140.Dl sysctl net.inet.carp.preempt=1
141.Pp
142Assume that host A is the preferred master and 192.168.1.x/24 is
143configured on one physical interface and 192.168.2.y/24 on another.
144This is the setup for host A:
145.Bd -literal -offset indent
146ifconfig carp0 create
147ifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.1/24
148ifconfig carp1 create
149ifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.2.1/24
150.Ed
151.Pp
152The setup for host B is identical, but it has a higher
153.Cm advskew :
154.Bd -literal -offset indent
155ifconfig carp0 create
156ifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.1/24
157ifconfig carp1 create
158ifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.2.1/24
159.Ed
160.Pp
161Because of the preempt option, when one of the physical interfaces of
162host A fails,
163.Cm advskew
164is adjusted to 240 on all its
165.Nm
166interfaces.
167This will cause host B to preempt on both interfaces instead of
168just the failed one.
169.Pp
170In order to set up an ARP balanced virtual host, it is necessary to configure
171one virtual host for each physical host which would respond to ARP requests
172and thus handle the traffic.
173In the following example, two virtual hosts are configured on two hosts to
174provide balancing and failover for the IP address 192.168.1.10.
175.Pp
176First the
177.Nm
178interfaces on host A are configured.
179The
180.Cm advskew
181of 100 on the second virtual host means that its advertisements will be sent
182out slightly less frequently.
183.Bd -literal -offset indent
184ifconfig carp0 create
185ifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.10/24
186ifconfig carp1 create
187ifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.1.10/24
188.Ed
189.Pp
190The configuration for host B is identical, except the
191.Cm advskew
192is on virtual host 1 rather than virtual host 2.
193.Bd -literal -offset indent
194ifconfig carp0 create
195ifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.10/24
196ifconfig carp1 create
197ifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.1.10/24
198.Ed
199.Pp
200Finally, the ARP balancing feature must be enabled on both hosts:
201.Pp
202.Dl sysctl net.inet.carp.arpbalance=1
203.Pp
204When the hosts receive an ARP request for 192.168.1.10, the source IP address
205of the request is used to compute which virtual host should answer the request.
206The host which is master of the selected virtual host will reply to the
207request, the other(s) will ignore it.
208.Pp
209This way, locally connected systems will receive different ARP replies and
210subsequent IP traffic will be balanced among the hosts.
211If one of the hosts fails, the other will take over the virtual MAC address,
212and begin answering ARP requests on its behalf.
213.Pp
214Note: ARP balancing only works on the local network segment.
215It cannot balance traffic that crosses a router, because the router
216itself will always be balanced to the same virtual host.
217.Sh SEE ALSO
218.Xr inet 4 ,
219.Xr rc.conf 5 ,
220.Xr ifconfig 8 ,
221.Xr sysctl 8
222.Sh HISTORY
223The
224.Nm
225device first appeared in
226.Ox 3.5 .
227The
228.Nm
229device was imported into
230.Fx 5.4 .
231