Providing IP addresses on your LAN

From freebsd.xn--wesstrm-f1a.se

Jump to: navigation, search

Contents

Overview

The computers on your internal LAN should all be configured with static IP addresses but for various reasons it's sometimes good to have a DHCP server available so new computers can have an IP address automatically. This will also be your first use of the FreeBSD Ports Collection since there is no DHCP server in the base operating system.

Instructions

More make.conf settings

When you install applications from the Ports Collection they will automatically install other applications they depend upon unless they're not already present in the system. To make absolutely sure there's no X and gui related software pulled in, you should type the line below which will add the necessary directive to /etc/make.conf.

# echo WITHOUT_X11=yes >> /etc/make.conf

Installing

There are two ways you can install software from the Ports Collection. You can either download pre-compiled binaries or you can download the source code and compile yourself. The second method will be the preferred one in this tutorial and is not that difficult since the Ports Collection framework take care of all the details. Finding the right folder for the software you want to install might be a little difficult even though there are ways to search. For now you will be guided to the correct location whenever a port needs to be installed.

# cd /usr/ports/net/isc-dhcp30-server

Compile the software.

# make
The configuration screen at right will appear. Many ports have options that can be altered to your likings at compile time and this is how you get to change them. You don't have this option if you install pre-compiled binaries. Instead you have to accept whatever the developer decided to include in the pre-compiled package.

In this particular case, the default options are perfectly fine. Simply highlight OK and press Enter and the source code will be downloaded and compilation begin.

Isc-dhcp3-server.png
Note: In later versions of isc-dhcp-server you need to disable the JAIL option or you will get a compile error.

If no errors occur you can go ahead and install the compiled code. The clean argument removes all the temporary working folders after the install. You should always do that to avoid problems later on when you want to upgrade the application.

# make install clean

Whenever the installation of a port has finished, you should pay attention to the output on the screen. It will tell you what configuration files needs to be modified and what options are available. In the case of the DHCP server there's a lot of output but if you scroll up a little you will find these important lines:

****  To setup dhcpd, you may have to copy /usr/local/etc/dhcpd.conf.sample
      to /usr/local/etc/dhcpd.conf for editing.

****  This port installs dhcp daemon, but don't invokes dhcpd by default. If
      you want to invoke dhcpd at startup, put these lines into /etc/rc.conf.

	    dhcpd_enable="YES"				# dhcpd enabled?
	    dhcpd_flags="-q"				# command option(s)
	    dhcpd_conf="/usr/local/etc/dhcpd.conf"	# configuration file
	    dhcpd_ifaces=""				# ethernet interface(s)
	    dhcpd_withumask="022"			# file creation mask</pre>

As you can see you need to create a configuration file for the DHCP server and also add a few lines to /etc/rc.conf as usual to have it start automatically.

dhcpd.conf

Now is a good time to learn that the configuration files for applications installed from the ports are always placed in /usr/local/etc while the configuration files for the base operating system are placed in /etc. This is an important FreeBSD design philosophy.

You can study the sample configuration file listed above if you like but for simplicity I will provide a suitable configuration file below. Start by creating an empty configuration file with the editor.

# ee /usr/local/etc/dhcpd.conf

Copy and paste the following lines:

option domain-name "pp.dyndns.biz";
option domain-name-servers 192.168.69.1;

authoritative;
default-lease-time 604800;
max-lease-time 1209600;

ddns-update-style none;

subnet 192.168.69.0 netmask 255.255.255.0 {
  range 192.168.69.32 192.168.69.63;
  option routers 192.168.69.1;
}

There are five references here to the network number of your internal LAN. This example use the value 69 but you have to change it to whatever you choose when you configured your internal NIC. The IP addresses that this DHCP server will send to the requesting clients are defined with the range parameter and should be set to something that doesn't conflict with anything else on your network. In this example it will allocate every address from 192.168.69.32 to 192.168.69.63 inclusive. Also, the domain-name should be the domain name you registered at DynDNS.

Starting it automatically

You should know by now that you use /etc/rc.conf to start services automatically at boot time. Open the file in the editor.

# ee /etc/rc.conf

Then copy and paste the start information printed on the screen when the program was installed - with one minor addition: dhcpd_ifaces should point to the interface name where the DHCP server should listen for requests, which of course should be the name of the network card for your internal LAN.

dhcpd_enable="YES"
dhcpd_flags="-q"
dhcpd_conf="/usr/local/etc/dhcpd.conf"
dhcpd_ifaces="em0"
dhcpd_withumask="022"

There were other options printed too but they're not necessary for the DHCP server to function. You add them if they provide functionality you wish to have and if you know what you're doing.

Save the file and then start the service manually to check that no errors are generated.

# /usr/local/etc/rc.d/isc-dhcpd start
Starting dhcpd.

Summary

  • Configuration files for services in the base operating system are stored in /etc
  • Start/stop scripts for services in the base operating system are stored in /etc/rc.d
  • Configuration files for applications in the Ports Collection are stored in /usr/local/etc
  • Start/stop scripts for applications in the Ports Collection are stored in /usr/local/etc/rc.d
  • Every port has its own folder below /usr/ports
  • To compile a port - change your current folder to the port's folder and type make. To install the port after compilation, type make install clean.
  • /usr/local/etc/dhcpd.conf is the configuration file for the DHCP server.
  • /usr/local/etc/rc.d/isc-dhcpd is the start/stop script for the DHCP server.

References


Next guide: Firewall setup
Personal tools