FreeBSD Server Setup

This page is work in progress. It will contain a guide to setup a FreeBSD server featuring mail, http, etc. using technology like zfs, nginx, ezjail, etc. Stay tuned for updates

Flattr: 

Add Loopback Network Interface with Alias on FreeBSD

Note that this page will be part of a documentation about setting up a server using FreeBSD with similar features to the existing server documentation. Also note that this page is still work in progress

To use EzJail on a FreeBSD host, e. g. to sandbox different services, you need to add a loopback network interface and add some aliases to it. Jails networking seems to require a dedicated network and loopback aliases can not run on the external interface. Follow the next paragraphs to add one loopback interface including three aliases.
First, create the loopback interface in rc.conf:

cloned_interfaces="lo1"

Then, add some aliases to the loopback interface in rc.conf:

ifconfig_lo1_alias0="inet 10.1.1.1 netmask 255.255.255.0"
ifconfig_lo1_alias1="inet 10.1.1.2 netmask 255.255.255.0"
ifconfig_lo1_alias1="inet 10.1.1.3 netmask 255.255.255.0"

If you happen to add an alias to an already running server, you might want to avoid rebooting and therefore also invoke the following command to add the alias while keeping the system running:

ifconfig lo1 alias 10.1.1.3 netmask 255.255.255.0 

That’s it.
iss

Flattr: 

Exchange a broken hard drive in a running ZFS pool

If one of your hard drives dies on your FreeBSD server, you need to format the new hard disk in the exactly same layout as the existing/previous disk was formatted. Last time when one of my hard drives started failing, I used the following steps to match up the partition layout between the new and the old (still working) hard drive. First I figured out the layout of the existing hard disk (in this case ada1)

gpart show ada1
=>        34  3907029101  ada1  GPT  (1.8T)
          34           6        - free -  (3.0K)
          40         128     1  freebsd-boot  (64K)
         168     8388608     2  freebsd-swap  (4.0G)
     8388776  3898640352     3  freebsd-zfs  (1.8T)
  3907029128           7        - free -  (3.5K)

Then I created the GPT on the new disk (ada0):

gpart create -s gpt ada0

Add the boot section:

gpart add -b 40 -s 128 -t freebsd-boot ada0

Set the boot code:

gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

Create the swap partition:

gpart add -s 8388608 -t freebsd-swap -l swap10 ada0

Add the ZFS partition:

gpart add -t freebsd-zfs -l disk10 ada0

Then take the disk online:

zpool online tank /dev/ada0p3

And finally start resilvering:

zpool replace tank /dev/ada0p3

That’s it.
iss

Flattr: