You get a bonus - 1 coin for daily activity. Now you have 1 coin

FreeBSD: installing and configuring a DHCP server

Practice



The task is simple: install and configure a DHCP server on a machine running FreeBSD.

To accomplish the task we'll use the ISC-DHCP daemon, and, as recommended, it will run in a chroot environment.


0) Don't forget to update the ports tree via portsnap fetch && portsnap update, so as not to run into a situation where the ports system tries to find the needed files of old versions or in old locations.


1) Installing.

$ cd /usr/ports/net/isc-dhcp42-server
$ sudo make install clean

A configuration screen will pop up right away, in which you should check the DHCP_PARANOIA option (this is specifically so the DHCP server can run in chroot mode).


2) After installation, go into /usr/local/etc and edit the dhcpd.conf file. It already contains examples of working configurations, but for simplicity I'll show an example of an already-cleaned-up version of such a file (a very simple example):

optio n domain-name-servers 192.168.0.1;
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
authoritative;
log-facility local7;

subnet 192.168.0.0 netmask 255.255.255.0 {
  option routers 192.168.0.1;
  option broadcast-address 192.168.0.255;
  range 192.168.0.100 192.168.0.200;
}

Here a subnet of 192.168.0.0/24 is declared for lease, starting from IP=192.168.0.100 and ending (inclusive) at IP=192.168.0.200. The default gateway is specified as 192.168.0.1, and the DNS server is the same address.


3) Now let's edit the file /etc/rc.conf and add the following entries to it:
dhcpd_enable="YES"
dhcpd_flags="-q"
dhcpd_conf="/usr/local/etc/dhcpd.conf"
dhcpd_ifaces="fxp0"
dhcpd_withumask="022"
dhcpd_chuser_enable="YES"
dhcpd_withuser="dhcpd"
dhcpd_withgroup="dhcpd"
dhcpd_chroot_enable="YES"
dhcpd_devfs_enable="YES"
dhcpd_rootdir="/var/db/dhcpd"

The lines from "dhcpd_chuser_enable" onward instruct the daemon to run via chroot.

The "-q" flag tells the daemon not to clutter the console with messages (otherwise dhcpd will intensively spam comments about all its actions). If the daemon fails to start and complains - you can disable this flag and see what it writes, to find where the error is.

The "fxp0" interface in the "dhcpd_ifaces=" line specifies which network card to listen for DHCP requests on and, accordingly, respond on. If there are several cards, list them separated by spaces.

4) That's essentially it. Now all that's left is to start dhcpd:
$ sudo /usr/local/etc/rc.d/isc-dhcpd start



5) What about multiple network cards?

Below is a config for the case where the server has several network cards, each of which needs its own range and its own subnet. In our case these are VLAN interfaces, but you can use any mix - even 10 physical cards.

option domain-name-servers 10.0.0.1;
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
authoritative;
log-facility local7;

shared-network vlan10 {
        subnet 10.0.10.0 netmask 255.255.255.0 {
                option routers 10.0.10.1;
                option broadcast-address 10.0.10.255;
                range 10.0.10.100 10.0.10.200;
        }
}
shared-network vlan11 {
        subnet 10.0.11.0 netmask 255.255.255.0 {
                option routers 10.0.11.1;
                option broadcast-address 10.0.11.255;
                range 10.0.11.100 10.0.11.200;
        }
}
shared-network vlan12 {
        subnet 10.0.12.0 netmask 255.255.255.0 {
                option routers 10.0.12.1;
                option broadcast-address 10.0.12.255;
                range 10.0.12.100 10.0.12.200;
        }
}

Correspondingly, in the config above - the network interfaces vlan10, vlan11, and vlan12 must be assigned IPs from the specified subnets.

PS. Don't forget to list all these network interfaces in /etc/rc.conf in the dhcpd_ifaces parameter.

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Computer networks"

Terms: Computer networks