LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices


Reply
  Search this Thread
Old 10-19-2005, 12:00 PM   #1
blood_omen
Member
 
Registered: Apr 2004
Location: Canada
Distribution: OpenBSD 3.6, Slackware 10.1
Posts: 134

Rep: Reputation: 15
DHCP Server Question


Greetings:

I have the following challenge ahead of me. I need to get a FreeBSD machine to handle the dhcp requests on my network. I'm currently using windows server t do this, but I would like to move from windows.

Many will say, well, and what is the problem, is fairly easy to configure dhcpd. Just follow the handbook. Yes, I already searched the handbook and yes it gave me some answers, but the problem arises here:

What I would like to do is create a pool of addresses and assign them against my hosts MAC addresses. In other words, create a table of MAC addresses, and when any client request the dhcpd, it will check the MAC address; if the client mac address exist in the table, the dhcpd assign an IP address and all related information, and if it does not exist, well, obvious, the client won't get IP.

There is nothing about it in the handbook, right now I'm reading the dhcpd man pages looking for some answers, but I also decided to post here for any guidance, link to documentation or any kind of tips that could be of use.

I thank you all in advance, have a nice day.
 
Old 10-20-2005, 01:44 PM   #2
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
How many clients are we talking about here? And do you want static ips for each computer (this is probably the easiest way)?
 
Old 10-20-2005, 02:48 PM   #3
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
Okay, I have been playing with this a little and decided to make a little script which could turn a little table into a complete dhcpd.conf file for use.

First the script:
Code:
#!/bin/sh
# Use this to parse a file of the following format to create a
# dhcpd.conf file for your network.
# Format of each line in the file:
# {macaddress}[,[ipaddress][,hostname]] 
# the things in []'s are optional.

HIGHBITS=10.0.0
NETMASK=255.255.255.0
BROADCAST=10.0.0.255
ROUTER=10.0.0.1
DOMAIN="foo.com"
NS="10.0.0.1, 65.0.0.4, 54.0.0.1"
HOSTNAME="host"
STARTNUM=2
HIGHNUM=22
ADDRESSFILE=~/tmp/macs.dat
OUTPUT=~/tmp/dhcpd.conf

header() 
{
	echo "deny unknown-clients;" > $OUTPUT
	echo "ddns-update-style ad-hoc;" >> $OUTPUT
	echo " " >> $OUTPUT
	echo "option routers ${ROUTER};" >> $OUTPUT
	echo "option broadcast-address ${BROADCAST};" >> $OUTPUT
	echo "option domain-name \"${DOMAIN}\";" >> $OUTPUT
	echo "option domain-name-servers ${NS};" >> $OUTPUT
	echo " " >> $OUTPUT
	echo "subnet ${HIGHBITS}.0 netmask ${NETMASK} {" >> $OUTPUT
	echo "range ${HIGHBITS}.${STARTNUM} ${HIGHBITS}.${HIGHNUM};" >> $OUTPUT
	echo "default-lease-time 604800;" >> $OUTPUT
	echo "max-lease-time 604800;" >> $OUTPUT
	echo "}" >> $OUTPUT
}

	

CURRENT=$STARTNUM
MACS=`cat ${ADDRESSFILE}`

header

for mac in $MACS
do
	macn=`echo $mac | awk 'BEGIN{FS=","}{print $1}'`
	ip=`echo $mac | awk 'BEGIN{FS=","}{print $2}'`
	host=`echo $mac | awk 'BEGIN{FS=","}{print $3}'`
	echo " " >> $OUTPUT
	if [ "x${host}" != "x" ]; then
		echo "host ${host} {" >> $OUTPUT
	else
		echo "host ${HOSTNAME}-${CURRENT} {" >> $OUTPUT
		CURRENT=`expr ${CURRENT} + 1`
	fi
	echo "hardware ethernet ${macn};" >> $OUTPUT
	if [ "x${ip}" != "x" ]; then
		echo "fixed-address ${ip};" >> $OUTPUT
	fi
	echo "}" >> $OUTPUT
done
Use this to parse a file which looks like this (using real numbers obviously):
Code:
ff:07:6b:32:d2:55,10.0.0.23,fnord
ff:0b:db:0d:a1:af
ff:03:47:b7:a9:ed,,laptop
ff:14:6c:00:bd:8b,10.0.0.2,wlan
ff:07:5b:ec:02:99,10.0.1.20
And it will produce this configuration file:
Code:
deny unknown-clients;
ddns-update-style ad-hoc;
 
option routers 10.0.0.1;
option broadcast-address 10.0.0.255;
option domain-name "foo.com";
option domain-name-servers 10.0.0.1, 65.0.0.4, 54.0.0.1;
 
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.2 10.0.0.22;
default-lease-time 604800;
max-lease-time 604800;
}
 
host fnord {
hardware ethernet ff:07:6b:32:d2:55;
fixed-address 10.0.0.23;
}
 
host host-2 {
hardware ethernet ff:0b:db:0d:a1:af;
}
 
host laptop {
hardware ethernet ff:03:47:b7:a9:ed;
}
 
host wlan {
hardware ethernet ff:14:6c:00:bd:8b;
fixed-address 10.0.0.2;
}
 
host host-3 {
hardware ethernet ff:07:5b:ec:02:99;
fixed-address 10.0.1.20;
}
Note: This is setup to automatically deny any client which has an unknown mac address (it's in the deny line). If you look at the lines in the mac address file you can see pretty much how to setup whatever you want.

Any other changes you would make or differences you want can be done by just editing the script for your needs.

Last edited by frob23; 10-20-2005 at 08:03 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
dhcp client not getting IP from dhcp server jkmartha Linux - Networking 2 06-17-2005 08:12 AM
quick question. dhcp server + bridge emetib Linux - Networking 2 06-02-2005 07:56 PM
how can a DHCP client get the DHCP server IP? AshesOfTime Linux - Networking 3 11-24-2004 06:50 AM
XP Pro Build 2600/sp1 v.1105 DHCP Client to Redhat 8.0 DHCP Server - Problems atomant Linux - Networking 5 06-28-2003 11:24 AM
How do you make the ip masquerade server/dhcp server broadcast dns to lan cmisip Linux - Networking 6 01-25-2003 10:43 PM

LinuxQuestions.org > Forums > Other *NIX Forums > *BSD

All times are GMT -5. The time now is 08:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration