2 .\" Copyright (c) 2003, Ryan McBride. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\" $OpenBSD: carp.4,v 1.16 2004/12/07 23:41:35 jmc Exp $
26 .\" $FreeBSD: src/share/man/man4/carp.4,v 1.10 2006/06/07 10:26:51 glebius Exp $
27 .\" $DragonFly: src/share/man/man4/carp.4,v 1.3 2007/08/18 18:04:59 swildner Exp $
34 .Nd Common Address Redundancy Protocol
37 .Cd "pseudo-device carp"
41 interface is a pseudo-device that implements and controls the
43 CARP allows multiple hosts on the same local network to share a set of IP addresses.
44 Its primary purpose is to ensure that these
45 addresses are always available, but in some configurations
47 can also provide load balancing functionality.
51 interface can be created at runtime using the
52 .Nm ifconfig Li carp Ns Ar N Cm create
53 command or by configuring
62 the administrator needs to configure at minimum a common virtual host ID (VHID)
63 and virtual host IP address on each machine which is to take part in the virtual
65 Additional parameters can also be set on a per-interface basis:
69 which are used to control how frequently the host sends advertisements when it
70 is the master for a virtual host, and
72 which is used to authenticate
78 .Dq "advertisement base" .
79 It is measured in seconds and specifies the base of the advertisement interval.
83 .Dq "advertisement skew" .
84 It is measured in 1/256 of seconds.
85 It is added to the base advertisement interval to make one host advertise
86 a bit slower that the other does.
91 are put inside CARP advertisements.
92 These configurations can be done using
98 Additionally, there are a number of global parameters which can be set using
100 .Bl -tag -width ".Va net.inet.carp.arpbalance"
101 .It Va net.inet.carp.allow
106 .It Va net.inet.carp.preempt
107 Allow virtual hosts to preempt each other.
108 It is also used to failover
110 interfaces as a group.
111 When the option is enabled and one of the
113 enabled physical interfaces
116 is changed to 240 on all
119 See also the first example.
121 .It Va net.inet.carp.log
122 Value of 0 disables any logging.
123 Value of 1 enables logging of bad
126 Values above 1 enable logging state changes of
130 .It Va net.inet.carp.arpbalance
131 Balance local traffic using ARP (see below).
133 .It Va net.inet.carp.suppress_preempt
134 A read only value showing the status of preemption suppression.
135 Preemption can be suppressed if link on an interface is down
138 interface is not synchronized.
139 Value of 0 means that preemption is not suppressed, since no
140 problems are detected.
141 Every problem increments suppression counter.
143 .Sh ARP LEVEL LOAD BALANCING
146 has limited abilities for load balancing the incoming connections
147 between hosts in Ethernet network.
148 For load balancing operation, one needs several CARP interfaces that
149 are configured to the same IP address, but to a different VHIDs.
150 Once an ARP request is received, the CARP protocol will use a hashing
151 function against the source IP address in the ARP request to determine
152 which VHID should this request belong to.
153 If the corresponding CARP interface is in master state, the ARP request
154 will be replied, otherwise it will be ignored.
157 section for a practical example of load balancing.
159 The ARP load balancing has some limitations.
160 First, ARP balancing only works on the local network segment.
161 It cannot balance traffic that crosses a router, because the
162 router itself will always be balanced to the same virtual host.
163 Second, ARP load balancing can lead to asymmetric routing
164 of incoming and outgoing traffic, and thus combining it with
166 is dangerous, because this creates a race condition between
167 balanced routers and a host they are serving.
168 Imagine an incoming packet creating state on the first router, being
169 forwarded to its destination, and destination replying faster
170 than the state information is packed and synced with the second router.
171 If the reply would be load balanced to second router, it will be
172 dropped due to no state.
174 For firewalls and routers with multiple interfaces, it is desirable to
177 interfaces together, when one of the physical interfaces goes down.
178 This is achieved by the preempt option.
179 Enable it on both host A and B:
181 .Dl sysctl net.inet.carp.preempt=1
183 Assume that host A is the preferred master and 192.168.1.x/24 is
184 configured on one physical interface and 192.168.2.y/24 on another.
185 This is the setup for host A:
186 .Bd -literal -offset indent
187 ifconfig carp0 create
188 ifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.1/24
189 ifconfig carp1 create
190 ifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.2.1/24
193 The setup for host B is identical, but it has a higher
195 .Bd -literal -offset indent
196 ifconfig carp0 create
197 ifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.1/24
198 ifconfig carp1 create
199 ifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.2.1/24
202 Because of the preempt option, when one of the physical interfaces of
205 is adjusted to 240 on all its
208 This will cause host B to preempt on both interfaces instead of
211 In order to set up an ARP balanced virtual host, it is necessary to configure
212 one virtual host for each physical host which would respond to ARP requests
213 and thus handle the traffic.
214 In the following example, two virtual hosts are configured on two hosts to
215 provide balancing and failover for the IP address 192.168.1.10.
219 interfaces on host A are configured.
222 of 100 on the second virtual host means that its advertisements will be sent
223 out slightly less frequently.
224 .Bd -literal -offset indent
225 ifconfig carp0 create
226 ifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.10/24
227 ifconfig carp1 create
228 ifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.1.10/24
231 The configuration for host B is identical, except the
233 is on virtual host 1 rather than virtual host 2.
234 .Bd -literal -offset indent
235 ifconfig carp0 create
236 ifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.10/24
237 ifconfig carp1 create
238 ifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.1.10/24
241 Finally, the ARP balancing feature must be enabled on both hosts:
243 .Dl sysctl net.inet.carp.arpbalance=1
245 When the hosts receive an ARP request for 192.168.1.10, the source IP address
246 of the request is used to compute which virtual host should answer the request.
247 The host which is master of the selected virtual host will reply to the
248 request, the other(s) will ignore it.
250 This way, locally connected systems will receive different ARP replies and
251 subsequent IP traffic will be balanced among the hosts.
252 If one of the hosts fails, the other will take over the virtual MAC address,
253 and begin answering ARP requests on its behalf.
263 device first appeared in