# CARP made easy



## drobison (Nov 8, 2010)

Here's the quick and dirty on how I got CARP working. I got most of the info from a few sites I found with Google, but none of them laid it out as clearly as I'd have preferred.

This example uses two servers, carp1.domain.com and carp2.domain.com, each of which is capable of acting as server.domain.com (the persistent host.)

First, include the following device in the kernel config. Build and install the CARP-enabled kernel.


```
device		carp
```

carp1.domain.com and carp2.domain.com are each capable of acting as server.domain.com. carp1 and carp2 are connected to the 192.168.10.0/24 network on bge0, and are connected to each other via crossover cable on the 192.168.20.0/24 network on bge1.

192.168.10.140 is server
192.168.10.141 is carp1
192.168.10.142 is carp2

In /etc/sysctl.conf add the line:


```
net.inet.carp.preempt=1
```

Make sure this sysctl is activated by issuing a command line directive as root:

`% sysctl net.inet.carp.preempt=1`

Here are the important bits of the /etc/rc.conf file for carp1:


```
hostname="carp1.domain.com"
ifconfig_bge0="inet 192.168.10.141  netmask 255.255.255.0"
ifconfig_bge1="inet 192.168.20.2  netmask 255.255.255.0"
defaultrouter="192.168.10.1"

cloned_interfaces="carp1 carp2"
ifconfig_carp1="vhid 10 advskew 50 pass PASSWORD1 192.168.10.140/24"
ifconfig_carp2="vhid 20 advskew 50 pass PASSWORD2 192.168.20.1/24"
```

And here are the important bits of the /etc/rc.conf file for carp2:


```
hostname="carp2.domain.com"

ifconfig_bge0="inet 192.168.10.142  netmask 255.255.255.0"
ifconfig_bge1="inet 192.168.20.3  netmask 255.255.255.0"
defaultrouter="192.168.10.1"

cloned_interfaces="carp1 carp2"
ifconfig_carp1="vhid 10 advskew 80 pass PASSWORD1 192.168.10.140/24"
ifconfig_carp2="vhid 20 advskew 80 pass PASSWORD2 192.168.20.1/24"
```

Make sure that server.domain.com, carp1.domain.com and carp2.domain.com are set up in your DNS. 

to enable carp use:

`% ifconfig carp1 up`
`% ifconfig carp2 up`

You should get some messages in /var/log/messages including lines like this:


```
carp0: 2 link states coalesced
carp1: 2 link states coalesced
```

Ping server.domain.com.  Determine which of your CARP hosts is currently acting as the master, and unplug its ethernet cable. The ping should continue just fine as the other CARP machine assumes the duties of server.domain.com. 

Enjoy.


----------



## rbelk (Nov 9, 2010)

That has got to be the easiest howto on carp I have seen. Thanks drobison!


----------



## fcgoo (May 13, 2011)

Good article! 
But I have a doubt that if to put these servers into ISP's room, is there three ip addresses to have, or the one ip expose to internetwork , and how to do it ?


----------

