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@slackware:# cd /tmp |
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@slackware:~# slackpkg install dhcpd
- root@slackware:~# 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@slackware:~# slackpkg search dhcp |
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@slackware:~# 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@slackware:~# cd /etc/ |
Let's see what is in the configuration file:
root@slackware:/etc# cat dhcpd.conf |
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@slackware:~# cp /usr/doc/dhcp-3.0.6/examples/dhcpd.conf /etc/dhcpd.conf |
Update: Slackware64 14.1 has dhcpd.conf.example in /etc directory.
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 |
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 |
2 - In Slackware command line terminal, type cat > rc.dhcpd and enter. Right-click mouse to paste the code that you copy just now. See example below:
root@slackware:~# cat > 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@slackware:~# less rc.dhcpd |
Now add the lines below to the /etc/rc.d/rc.local file to start dhcpd at boot:
if [ -x /etc/rc.d/rc.dhcpd ]; then |
Let's start the dhcpd service now:
root@slackware:~# /etc/rc.d/rc.dhcpd start |
We can check to see if dhcpd daemon is running using daemon status check. See example below:
root@slackware:~# /etc/rc.d/rc.dhcpd status |
The example shows that dhcpd is not running. There must be something wrong. We 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. See example below:
root@slackware:~# cat /var/log/syslog |
The example above shows that we are missing a semicolon in the /etc/dhcpd.conf file. Actually we got semicolon there but the exact error dhcpd daemon won't start is we need to put a comma to separate two dns ip addresses. So go back and fix the error and start dhcpd daemon again. When dhcpd daemon successfully started, then we can test client computer to connect to the Slackware dhcp server.
Setup dhcp client on Windows Vista
The dhcp server is ready, now it's time to setup dhcp client. Here is the example to setup dhcp client in Windows Vista. Click Start, choose All Programs and right-click Network. Choose Properties. See picture below:
In Windows Vista Network Properties, choose View Status (Windows 7 changes the name to Local Area Connection). See image below:
When you click 'View Status', the Local Area Connection Status window pops up. Here we just click Properties. See image below:
Now the Local Area Network Properties window pops up. We choose Internet protocol version 4 and click Properties. See image below:
In this window, make sure both Obtain an IP address automatically button and Obtain DNS server address automatically are clicked. Click OK and we are done. See picture below: