I have file like this ip_mac which contain student year and their respective mac address. I want to allow only them to have dhcp leases. Is it possible in ubuntu to perform such.

94:92:66:38:a6:79                             "Prajwal Bhandary"                       2017            cs            Mob
30:e1:71:c9:1b:43                             "Prajwal Bhandary"                       2017            cs            Lan
94:65:2d:23:a8:4d                             "Unique Karki"                           2017            cs            Mob
84:8f:69:ca:15:00                             "Anup Paudel"                            2017            arch          Mob
88:83:22:eb:1e:41                             "Anup Paudel"                            2017            arch          Lan

and any student can be added to any part so if i restart isc dhcp server student should not be disconnected.

One way was to use format like this in /etc/dhcp/dchpd.conf

host student1 {
hardware ethernet 94:92:66:38:a6:79;

but the problem is i need to set ip for each student. And there are more than 400 so managing ip is night mare right?

another way was to default allow but we have ip limitations like only 500 ip so if unnecessary people connect student cannot use so is there is solution to such situation?


Can you just use mac address and allow dhcp leases instead of writing fixed-address

Is it possible to allow dhcp leases by scanning file like that?

  • what's wrong with running that input file through a shell script to generate a dhcp.conf? You can't be changing it very often! – JayEye Mar 17 '18 at 8:46
  • @JayEye we can use shell script but how do i know whichh ip should i give to them. Inserting random ip everything makes messy right? – aftershock Mar 17 '18 at 10:12
  • The same way you would do it if you built dhcpd.conf manually! – JayEye Mar 17 '18 at 16:42
  • JayEye in dhcpd we need to specify ip manually isn't it? Is there no way i can only specify mac in dhcpd file no ip. ? – aftershock Mar 19 '18 at 15:16

I made this script from one of an old script I keep.


if [ "$EUID" -ne 0 ];
  then echo "Please run as root (sudo)"


DATE=`date '+%Y-%m-%d %H:%M'`


echo ""
echo "|==========================================================|"
echo "|**********************************************************|"
echo "|                       DHCP CONF                          |"
echo "|   Welcome to this configuration Script for DHCP Server.  |"
echo "|                                                          |"
echo "|**********************************************************|"
echo "|==========================================================|"
echo ""
echo "CTRL-C to leave"
echo ""

read -p "WARNING. The file $PATH_DHCP_FILE will be edit. Do you want to continue ? [yes] " AGREE

if [ "$AGREE" != 'yes' ]
  then echo "Stop script."

echo ""
echo "Please, fill the following informations (be care about the syntax)"
read -p "Network IP []: " IP
read -p "Netmask []: " NETMASK
read -p "IP Range []: " IP_RANGE

echo ""
echo "--DHCP Configuration--"
echo "----Append configuration to $PATH_DHCP_FILE----"
echo "

# ============================
# *DCHP Script configurations*
# ***$DATE***
subnet $IP netmask $NETMASK {
  range $IP_RANGE;
  deny unknown-clients;

include \"$PATH_DHCP_TRUST_FILE\";
# ============================

echo ""

echo "# ***$DATE***" >> $PATH_DHCP_TRUST_FILE
while IFS='' read -r line || [[ -n "$line" ]]; do
    echo "Text read from file: $line"
    studenMac=$(echo $line| cut -d' ' -f 1)
    student=$(echo $line| cut -d' ' -f 2)

    echo "Studen mac : $studenMac"
    echo "Studen host : $student"
    echo "Add $student with $studenMac"
    echo "host $student { hardware ethernet $studenMac; }" >> $PATH_DHCP_TRUST_FILE

Edit the PATH_DHCP_FILE, PATH_DHCP_TRUST_FILE and PATH_STUDENTS_FILE variables and complete when the script ask information.

There is the result in test file from my side :

For the file test.conf (/etc/dhcpd.conf)

# ============================
# *DCHP Script configurations*
# ***2018-03-19 17:36***
subnet  netmask {
  deny unknown-clients;

include "./trust_host";
# ============================

And in the file trust_host :

# ***2018-03-19 18:44***
host Prajwal { hardware ethernet 94:92:66:38:a6:79; }
host Prajwal { hardware ethernet 30:e1:71:c9:1b:43; }
host Unique { hardware ethernet 94:65:2d:23:a8:4d; }
host Anup { hardware ethernet 84:8f:69:ca:15:00; }
host Anup { hardware ethernet 88:83:22:eb:1e:41; }

Be care, I don't handle duplication.

I hope this help.

  • thanks it will really help me :) Will test it soon and give feedback – aftershock Mar 20 '18 at 3:57

You can restrict a pool of addresses with deny unknown-clients;. This way, only MAC addresses which appear in a host declaration will receive an IP.

And you don't need to specify a fixed-address in the host declaration.

A minimal (and untested) example might look like this

subnet netmask {
    # option routers;
    # option ... etc.

    pool {
            deny unknown-clients;

include "/etc/dhcpd/known-hosts.conf";

And in "/etc/dhcpd/known-hosts.conf", which should be easy to generate with a script from your MAC-addresses list :

host h1 { hardware ethernet 00:09:b0:48:ca:ec; }
host h2 { hardware ethernet 00:80:88:11:e0:9f; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.