LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   *BSD (https://www.linuxquestions.org/questions/%2Absd-17/)
-   -   DHCP Server Question (https://www.linuxquestions.org/questions/%2Absd-17/dhcp-server-question-374703/)

blood_omen 10-19-2005 12:00 PM

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.

frob23 10-20-2005 01:44 PM

How many clients are we talking about here? And do you want static ips for each computer (this is probably the easiest way)?

frob23 10-20-2005 02:48 PM

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.


All times are GMT -5. The time now is 06:34 AM.