18e925890SGleb Smirnoff.\" $OpenBSD: carp.4,v 1.16 2004/12/07 23:41:35 jmc Exp $ 28e925890SGleb Smirnoff.\" 38e925890SGleb Smirnoff.\" Copyright (c) 2003, Ryan McBride. All rights reserved. 48e925890SGleb Smirnoff.\" 58e925890SGleb Smirnoff.\" Redistribution and use in source and binary forms, with or without 68e925890SGleb Smirnoff.\" modification, are permitted provided that the following conditions 78e925890SGleb Smirnoff.\" are met: 88e925890SGleb Smirnoff.\" 1. Redistributions of source code must retain the above copyright 98e925890SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer. 108e925890SGleb Smirnoff.\" 2. Redistributions in binary form must reproduce the above copyright 118e925890SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer in the 128e925890SGleb Smirnoff.\" documentation and/or other materials provided with the distribution. 138e925890SGleb Smirnoff.\" 148e925890SGleb Smirnoff.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 158e925890SGleb Smirnoff.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 168e925890SGleb Smirnoff.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 178e925890SGleb Smirnoff.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 188e925890SGleb Smirnoff.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 198e925890SGleb Smirnoff.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 208e925890SGleb Smirnoff.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 218e925890SGleb Smirnoff.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 228e925890SGleb Smirnoff.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 238e925890SGleb Smirnoff.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 248e925890SGleb Smirnoff.\" SUCH DAMAGE. 258e925890SGleb Smirnoff.\" 268e925890SGleb Smirnoff.\" $FreeBSD$ 278e925890SGleb Smirnoff.\" 28442af10aSGleb Smirnoff.Dd February 25, 2005 298e925890SGleb Smirnoff.Dt CARP 4 308e925890SGleb Smirnoff.Os 318e925890SGleb Smirnoff.Sh NAME 328e925890SGleb Smirnoff.Nm carp 338e925890SGleb Smirnoff.Nd Common Address Redundancy Protocol 348e925890SGleb Smirnoff.Sh SYNOPSIS 358e925890SGleb Smirnoff.Cd "device carp" 368e925890SGleb Smirnoff.Sh DESCRIPTION 378e925890SGleb SmirnoffThe 388e925890SGleb Smirnoff.Nm 393e630869SGleb Smirnoffinterface is a pseudo-device that implements and controls the 408e925890SGleb SmirnoffCARP protocol. 413e630869SGleb SmirnoffCARP allows multiple hosts on the same local network to share a set of IP addresses. 428e925890SGleb SmirnoffIts primary purpose is to ensure that these 438e925890SGleb Smirnoffaddresses are always available, but in some configurations 448e925890SGleb Smirnoff.Nm 458e925890SGleb Smirnoffcan also provide load balancing functionality. 468e925890SGleb Smirnoff.Pp 478e925890SGleb SmirnoffA 488e925890SGleb Smirnoff.Nm 498e925890SGleb Smirnoffinterface can be created at runtime using the 503e630869SGleb Smirnoff.Nm ifconfig Li carp Ns Ar N Cm create 518e925890SGleb Smirnoffcommand or by setting up configuration in 528e925890SGleb Smirnoff.Pa /etc/rc.conf 538e925890SGleb Smirnofffile. 548e925890SGleb Smirnoff.Pp 558e925890SGleb SmirnoffTo use 568e925890SGleb Smirnoff.Nm , 578e925890SGleb Smirnoffthe administrator needs to configure at minimum a common virtual host ID and 588e925890SGleb Smirnoffvirtual host IP address on each machine which is to take part in the virtual 598e925890SGleb Smirnoffgroup. 608e925890SGleb SmirnoffAdditional parameters can also be set on a per-interface basis: 618e925890SGleb Smirnoff.Cm advbase 628e925890SGleb Smirnoffand 638e925890SGleb Smirnoff.Cm advskew , 648e925890SGleb Smirnoffwhich are used to control how frequently the host sends advertisements when it 658e925890SGleb Smirnoffis the master for a virtual host, and 668e925890SGleb Smirnoff.Cm pass 673e630869SGleb Smirnoffwhich is used to authenticate 683e630869SGleb Smirnoff.Nm 693e630869SGleb Smirnoffadvertisements. 708e925890SGleb SmirnoffFinally 718e925890SGleb Smirnoff.Cm carpdev 728e925890SGleb Smirnoffis used to specify which interface the 738e925890SGleb Smirnoff.Nm 748e925890SGleb Smirnoffdevice attaches to. 753e630869SGleb SmirnoffIf unspecified, the kernel attempts to set 763e630869SGleb Smirnoff.Cm carpdev 773e630869SGleb Smirnoffby looking for 788e925890SGleb Smirnoffanother interface with the same subnet. 798e925890SGleb SmirnoffThese configurations can be done using 808e925890SGleb Smirnoff.Xr ifconfig 8 , 818e925890SGleb Smirnoffor through the 828e925890SGleb Smirnoff.Dv SIOCSVH 833e630869SGleb Smirnoff.Xr ioctl 2 . 848e925890SGleb Smirnoff.Pp 858e925890SGleb SmirnoffAdditionally, there are a number of global parameters which can be set using 868e925890SGleb Smirnoff.Xr sysctl 8 : 873e630869SGleb Smirnoff.Bl -tag -width ".Va net.inet.carp.arpbalance" 883e630869SGleb Smirnoff.It Va net.inet.carp.allow 898e925890SGleb SmirnoffAccept incoming 908e925890SGleb Smirnoff.Nm 918e925890SGleb Smirnoffpackets. 928e925890SGleb SmirnoffEnabled by default. 933e630869SGleb Smirnoff.It Va net.inet.carp.preempt 948e925890SGleb SmirnoffAllow virtual hosts to preempt each other. 958e925890SGleb SmirnoffIt is also used to failover 968e925890SGleb Smirnoff.Nm 978e925890SGleb Smirnoffinterfaces as a group. 988e925890SGleb SmirnoffWhen the option is enabled and one of the 998e925890SGleb Smirnoff.Nm 1008e925890SGleb Smirnoffenabled physical interfaces 1013e630869SGleb Smirnoffgoes down, 1023e630869SGleb Smirnoff.Cm advskew 1033e630869SGleb Smirnoffis changed to 240 on all 1048e925890SGleb Smirnoff.Nm 1058e925890SGleb Smirnoffinterfaces. 1068e925890SGleb SmirnoffSee also the first example. 1078e925890SGleb SmirnoffDisabled by default. 1083e630869SGleb Smirnoff.It Va net.inet.carp.log 109442af10aSGleb SmirnoffValue of 0 disables any logging. 110442af10aSGleb SmirnoffValue of 1 enables logging of bad 1118e925890SGleb Smirnoff.Nm 1128e925890SGleb Smirnoffpackets. 113442af10aSGleb SmirnoffValues above 1 enable logging state changes of 114442af10aSGleb Smirnoff.Nm 115442af10aSGleb Smirnoffinterfaces. 116442af10aSGleb SmirnoffDefault value is 1. 1173e630869SGleb Smirnoff.It Va net.inet.carp.arpbalance 1188e925890SGleb SmirnoffBalance local traffic using ARP. 1198e925890SGleb SmirnoffDisabled by default. 1208e925890SGleb Smirnoff.El 1218e925890SGleb Smirnoff.Sh EXAMPLES 1228e925890SGleb SmirnoffFor firewalls and routers with multiple interfaces, it is desirable to 1238e925890SGleb Smirnofffailover all of the 1248e925890SGleb Smirnoff.Nm 1258e925890SGleb Smirnoffinterfaces together, when one of the physical interfaces goes down. 1268e925890SGleb SmirnoffThis is achieved by the preempt option. 1278e925890SGleb SmirnoffEnable it on both host A and B: 1288e925890SGleb Smirnoff.Pp 1293e630869SGleb Smirnoff.Dl sysctl net.inet.carp.preempt=1 1308e925890SGleb Smirnoff.Pp 1318e925890SGleb SmirnoffAssume that host A is the preferred master and 192.168.1.x/24 is 1328e925890SGleb Smirnoffconfigured on one physical interface and 192.168.2.y/24 on another. 1338e925890SGleb SmirnoffThis is the setup for host A: 1348e925890SGleb Smirnoff.Bd -literal -offset indent 1353e630869SGleb Smirnoffifconfig carp0 create 1363e630869SGleb Smirnoffifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.1 \e 1378e925890SGleb Smirnoff 255.255.255.0 1383e630869SGleb Smirnoffifconfig carp1 create 1393e630869SGleb Smirnoffifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.2.1 \e 1408e925890SGleb Smirnoff 255.255.255.0 1418e925890SGleb Smirnoff.Ed 1428e925890SGleb Smirnoff.Pp 1433e630869SGleb SmirnoffThe setup for host B is identical, but it has a higher 1443e630869SGleb Smirnoff.Cm advskew : 1458e925890SGleb Smirnoff.Bd -literal -offset indent 1463e630869SGleb Smirnoffifconfig carp0 create 1473e630869SGleb Smirnoffifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat \e 1488e925890SGleb Smirnoff 192.168.1.1 255.255.255.0 1493e630869SGleb Smirnoffifconfig carp1 create 1503e630869SGleb Smirnoffifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat \e 1518e925890SGleb Smirnoff 192.168.2.1 255.255.255.0 1528e925890SGleb Smirnoff.Ed 1538e925890SGleb Smirnoff.Pp 1548e925890SGleb SmirnoffBecause of the preempt option, when one of the physical interfaces of 1553e630869SGleb Smirnoffhost A fails, 1563e630869SGleb Smirnoff.Cm advskew 1573e630869SGleb Smirnoffis adjusted to 240 on all its 1588e925890SGleb Smirnoff.Nm 1598e925890SGleb Smirnoffinterfaces. 1608e925890SGleb SmirnoffThis will cause host B to preempt on both interfaces instead of 1618e925890SGleb Smirnoffjust the failed one. 1628e925890SGleb Smirnoff.Pp 1638e925890SGleb SmirnoffIn order to set up an ARP balanced virtual host, it is necessary to configure 1648e925890SGleb Smirnoffone virtual host for each physical host which would respond to ARP requests 1658e925890SGleb Smirnoffand thus handle the traffic. 1668e925890SGleb SmirnoffIn the following example, two virtual hosts are configured on two hosts to 1678e925890SGleb Smirnoffprovide balancing and failover for the IP address 192.168.1.10. 1688e925890SGleb Smirnoff.Pp 1698e925890SGleb SmirnoffFirst the 1708e925890SGleb Smirnoff.Nm 1713e630869SGleb Smirnoffinterfaces on host A are configured. 1728e925890SGleb SmirnoffThe 1738e925890SGleb Smirnoff.Cm advskew 1748e925890SGleb Smirnoffof 100 on the second virtual host means that its advertisements will be sent 1758e925890SGleb Smirnoffout slightly less frequently. 1768e925890SGleb Smirnoff.Bd -literal -offset indent 1773e630869SGleb Smirnoffifconfig carp0 create 1783e630869SGleb Smirnoffifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.10 \e 1798e925890SGleb Smirnoff 255.255.255.0 1803e630869SGleb Smirnoffifconfig carp1 create 1813e630869SGleb Smirnoffifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat \e 1828e925890SGleb Smirnoff 192.168.1.10 255.255.255.0 1838e925890SGleb Smirnoff.Ed 1848e925890SGleb Smirnoff.Pp 1853e630869SGleb SmirnoffThe configuration for host B is identical, except the 1863e630869SGleb Smirnoff.Cm advskew 1873e630869SGleb Smirnoffis on virtual host 1 rather than virtual host 2. 1888e925890SGleb Smirnoff.Bd -literal -offset indent 1893e630869SGleb Smirnoffifconfig carp0 create 1903e630869SGleb Smirnoffifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat \e 1918e925890SGleb Smirnoff 192.168.1.10 255.255.255.0 1923e630869SGleb Smirnoffifconfig carp1 create 1933e630869SGleb Smirnoffifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.1.10 \e 1948e925890SGleb Smirnoff 255.255.255.0 1958e925890SGleb Smirnoff.Ed 1968e925890SGleb Smirnoff.Pp 1978e925890SGleb SmirnoffFinally, the ARP balancing feature must be enabled on both hosts: 1988e925890SGleb Smirnoff.Pp 1993e630869SGleb Smirnoff.Dl sysctl net.inet.carp.arpbalance=1 2008e925890SGleb Smirnoff.Pp 2018e925890SGleb SmirnoffWhen the hosts receive an ARP request for 192.168.1.10, the source IP address 2028e925890SGleb Smirnoffof the request is used to compute which virtual host should answer the request. 2038e925890SGleb SmirnoffThe host which is master of the selected virtual host will reply to the 2048e925890SGleb Smirnoffrequest, the other(s) will ignore it. 2058e925890SGleb Smirnoff.Pp 2068e925890SGleb SmirnoffThis way, locally connected systems will receive different ARP replies and 2078e925890SGleb Smirnoffsubsequent IP traffic will be balanced among the hosts. 2088e925890SGleb SmirnoffIf one of the hosts fails, the other will take over the virtual MAC address, 2098e925890SGleb Smirnoffand begin answering ARP requests on its behalf. 2108e925890SGleb Smirnoff.Pp 2118e925890SGleb SmirnoffNote: ARP balancing only works on the local network segment. 2128e925890SGleb SmirnoffIt cannot balance traffic that crosses a router, because the router 2138e925890SGleb Smirnoffitself will always be balanced to the same virtual host. 2148e925890SGleb Smirnoff.Sh SEE ALSO 2158e925890SGleb Smirnoff.Xr inet 4 , 2168e925890SGleb Smirnoff.Xr rc.conf 5 , 2178e925890SGleb Smirnoff.Xr ifconfig 8 , 2188e925890SGleb Smirnoff.Xr sysctl 8 2198e925890SGleb Smirnoff.Sh HISTORY 2208e925890SGleb SmirnoffThe 2218e925890SGleb Smirnoff.Nm 2228e925890SGleb Smirnoffdevice first appeared in 2238e925890SGleb Smirnoff.Ox 3.5 . 2248e925890SGleb SmirnoffThe 2258e925890SGleb Smirnoff.Nm 2263e630869SGleb Smirnoffdevice was imported into 2278e925890SGleb Smirnoff.Fx 5.4 . 228