*BSDThis forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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):
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.