1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
.\" $OpenBSD: carp.4,v 1.5 2003/12/08 10:03:43 markus 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 you would like to have actively
responding to ARP requests and thus handling the traffic.
In the following example, we will configure 2 hosts to provide balancing and
failover for the IP address 192.168.1.10.
.Pp
First, we configure the
.Nm
interfaces on Host A.
The
.Ar advskew
of 100 on the second virtual host means that it's 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
# ifconfig carp1 create
# ifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.1.10
.Ed
.Pp
Now we configure Host B.
The configuration is identical, except we skew virtual host 1 instead.
.Bd -literal -offset indent
# ifconfig carp0 create
# ifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.10
# ifconfig carp1 create
# ifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.1.10
.Ed
.Pp
Finally, the ARP balancing feature must be enabled on both hosts:
.Pp
.Dl # sysctl -w 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 ifconfig 8 ,
.Xr sysctl 8
.Sh HISTORY
The
.Nm
device first appeared in
.Ox 3.5 .
|