Install and configure dhcp server in Slackware Linux
A computer needs an ip address in order to communicate with other computer in a networking environment while a server needs to provide ip addresses for all its clients (users). There are two types of server that provide ip addresses to clients, a dynamic ip address server and static ip address server. A server that provides dynamic ip address is called a DHCP server (DHCP - Dynamic Host Configuration Protocol). That is the server that we are going to setup here.
Before we begin, let's look at how dhcp server works and some basic information about dhcp. A dhcp server not only handing over ip addresses to clients but also provides complete networking requirements such as subnet mask, DNS address and gateway router address. All these information are given automatically during boot up when a client has been configured to be a dhcp client.
A dhcp server is reasonable in a network environment where over 15 clients needed ip addresses. The reason is static ip addresses are hard to manage and in case of organization is planning for expenditure, dhcp is future proof. A dhcp server needs to be configured with a range of ip addresses that it can assign to network clients. When a client is boot up, it will provide an ip address along with other required addresses and prepare the next ip address in range for the next client. The ip address is never fix for one client, that's why it's called dynamic. When a client computer is shutdown, its ip address is released and can be assigned to another computer.That how a dhcp server works.
Install dhcp server in Slackware
A Linux server needs a dhcp service which is called a dhcpd (it's dhcp daemon) installed before dhcp can be configured. Slackware compiled dhcpd package is in /slackware-12.1/source/n/dhcp directory in Slackware installation dvd. It's recommended to download the latest dhcpd packages from Linux distribution's website or package maintainer website.
In Slackware Linux, installing a package is easy with a package utility called pkgtool. Pkgtool is a menu base tool. To use the utility, just type pkgtool in command line terminal. However you need to download whatever package you want to install because pkgtool can't get package from the Internet.
Go to Slackware packages website to download latest dhcpd package released.
Search current dhcpd package, choose nearest mirror and download it. Save dhcpd package in /tmp directory.
Change directory to /tmp. Type pkgtool at command line terminal.
root@musang:# cd /tmp root@musang:/tmp# pkgtool
Choose Current - Install packages from the current directory.
Choose Yes - Install package dhcp-3.0.6-i486-1.
Slackware also has software package management system called slackpkg which works similar to Debian aptitude. Slackpkg can automatically install and update software package via the Internet. You can install slackpkg from Slackware dvd in extra package. The steps for slackpkg installation from cd or dvd using pkgtool is the same as dhcp installation above. For more information about Slackware slackpkg, see slackpkg - Slackware package management system tutorial. Here is a slackpkg syntax to install and upgrade dhcpd package:
- root@musang:~# slackpkg install dhcpd
- root@musang:~# slackpkg upgrade dhcpd
When you invoke the slackpkg install dhcpd, dhcpd package will be downloaded from the chosen mirror when setting up slackpkg. If you experienced slow connectivity or dhcp download failed, choose other slackpkg mirror. That's all. With slackpkg, you just type the command, and slackpkg will do the rest.
Configure dhcp server in Slackware
The first step is done, now we are going to configure dhcp server in Slackware Linux. Before we continue, let's check whether dhcp package was successfully installed in our system:
root@musang:~# slackpkg search dhcp The list below shows all packages with the selected pattern. [ installed ] - kdelibs-3.5.9-i486-4 [ installed ] - dhcp-3.0.6-i486-1 [ installed ] - dhcpcd-2.0.4-i486-2 [ installed ] - iproute2-2.6.16_060323-i486-2 root@musang:~#
If you don't have slackpkg, use pkgtool to view the installed packages. You can also check dhcpd package in installed packages log with this command:
root@musang:~# ls -l /var/log/packages | grep dhcpd
A dhcp server configuration file is called dhcpd.conf. You can find it in /etc directory. Here, see this:
root@musang:~# cd /etc/ root@musang:/etc# ls -l | grep dhcp drwxr-xr-x 2 root root 4096 2006-07-26 14:09 dhcpc/ -rw-r--r-- 1 root root 75 2008-04-09 10:16 dhcpd.conf root@musang:/etc#
Let's see what is in the configuration file:
root@musang:/etc# cat dhcpd.conf
# dhcpd.conf
#
# Configuration file for ISC dhcpd (see 'man dhcpd.conf')
#
root@musang:/etc#
It's nothing inside. No dhcp configuration's example. Is that means we must start everything from zero? No, don't worry. We have an example of dhcp server configuration in /usr/doc/dhcp-3.0.6/examples/dhcpd.conf. So we just copy the dhcp configuration file and replace our dhcpd.conf file in /etc directory. Here we go:
root@musang:~# cp /usr/doc/dhcp-3.0.6/examples/dhcpd.conf
/etc/dhcpd.conf
root@musang:~#
What we need to do next is to use text editor and edit configuration for our network. Here is example of my dhcpd.conf configuration:
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
option domain-name "example.com";
option domain-name-servers 192.168.1.3;
default-lease-time 600;
max-lease-time 7200;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# A slightly different configuration for an internal subnet.
# I choose this section to edit for my local dhcp configuration
subnet 192.168.1.0 netmask 255.255.255.0 {
option domain-name "example.com";
option broadcast-address 192.168.1.254;
option domain-name-servers musang.example.com;
option subnet-mask 255.255.255.0;
option routers 192.168.1.1;
range 192.168.1.50 192.168.1.60;
default-lease-time 600;
max-lease-time 7200;
}
You can add a static server if you have it in your network. Just edit the default example configuration. After you are done setting up server and ip address required in the dhcpd.conf configuration file, save it. It's time to start the dhcp service (dhcp daemon) now.
Start dhcpd service
First we must enable dhcpd service in /etc/rc.d directory and make it executable. If you don't have /etc/rc.d/rc.dhcpd, then copy the code below and save it as rc.dhcpd. Here is the easy way to do it:
1 - Copy this code:
#!/bin/sh
#
# /etc/rc.d/rc.dhcpd
# This shell script takes care of starting and stopping
# the ISC DHCPD service
#
# Put the command line options here that you want to pass to dhcpd:
DHCPD_OPTIONS="-q eth0"
[ -x /usr/sbin/dhcpd ] || exit 0
[ -f /etc/dhcpd.conf ] || exit 0
start() {
# Start daemons.
echo -n "Starting dhcpd: /usr/sbin/dhcpd $DHCPD_OPTIONS "
/usr/sbin/dhcpd $DHCPD_OPTIONS
echo
}
stop() {
# Stop daemons.
echo -n "Shutting down dhcpd: "
killall -TERM dhcpd
echo
}
status() {
PIDS=$(pidof dhcpd)
if [ "$PIDS" == "" ]; then
echo "dhcpd is not running!"
else
echo "dhcpd is running at pid(s) ${PIDS}."
fi
}
restart() {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
;;
esac
exit 0
2 - In Slackware command line terminal, type cat > rc.httpd and enter. Right-click mouse to paste the code that you copy just now. See example below:
root@musang:~# cat > rc.dhcpd
#!/bin/sh
#
# /etc/rc.d/rc.dhcpd
#
# Start/stop/restart the DHCP daemon.
#
# To make dhcpd start automatically at boot, make this
# file executable: chmod 755 /etc/rc.d/rc.dhcpd
...
...
...
Press Ctrl+d to save and exit. You can view the file with less or cat command. Now move the rc.dhcpd file to /etc/rc.d/ directory. See complete step by step instructions example below:
root@musang:~# less rc.dhcpd root@musang:~# mv rc.dhcpd /etc/rc.d/rc.dhcpd root@musang:~# ls -l /etc/rc.d/rc.dhcpd -rw-r--r-- 1 root root 792 2008-12-02 15:47 /etc/rc.d/rc.dhcpd root@musang:~# chmod 755 /etc/rc.d/rc.dhcpd root@musang:~# ls -l /etc/rc.d/rc.dhcpd -rwxr-xr-x 1 root root 792 2008-12-02 15:47 /etc/rc.d/rc.dhcpd* root@musang:~#
Let's start the dhcpd service now:
root@musang:~# /etc/rc.d/rc.dhcpd start
Starting DHCPD...
root@musang:~#
You can troubleshoot dhcpd error by looking at the system's log. Use tail /var/log/syslog and tail /var/log/messages to read the last 10 logs. Carefully read the error and try suggestion given.
Popular content


Delicious
Digg
StumbleUpon
Propeller
Reddit
Newsvine
Furl
Facebook
Google
Yahoo
Technorati
Icerocket