LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 11-24-2010, 04:09 AM   #1
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Rep: Reputation: 58
how to do dhcpd to give a certain ip address based on mac address


Hello, Im trying to setup dhcpd to put certain systems witch have mac address starting with 08:00:* in a certain ip class.

How can this be done?

So any system with mac address starting with 08:00 to get an ip from this range 192.168.12.2-192.168.12.99.
 
Old 11-24-2010, 04:26 AM   #2
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Ubuntu 10.10, Slackware 64-current
Posts: 2,124

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
In your DHCP configuration you will want to create (or modify) a class or a zone. You can the create a "filter" that will match on a substring of the MAC address to identify that class. You then specify that members of that class receive IP addresses from a the desired pool. That sounds a lot more complicated than it really is, so here is an example:

Code:
  subnet 172.17.0.0 netmask 255.255.255.0 {
  class "myclass" {
  match if substring (hardware, 1, 2) = 08:00;
}

pool {
    allow members of "myclass";
    range 172.17.0.2 172.17.0.10;
}
 
Old 11-24-2010, 05:32 AM   #3
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Original Poster
Rep: Reputation: 58
I set it up like this:

subnet 192.168.12.0 netmask 255.255.255.0 {

class "virtualclass" {
match if substring (hardware, 1, 2) = 08:00;
}
}

pool {
allow members of "virtualclass";
range 192.168.12.2 192.168.12.99;
}

But it runs into an error:


dhcpd self-test failed. Please fix the config file.
The error was:
/etc/dhcp3/dhcpd.conf line 64: pool declared outside of network
pool
^
Configuration file errors encountered -- exiting
 
Old 11-24-2010, 05:35 AM   #4
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Original Poster
Rep: Reputation: 58
Sorry, my bad, suppose to be setup like this:


subnet 192.168.12.0 netmask 255.255.255.0 {
class "virtualclass" {
match if substring (hardware, 1, 2) = 08:00;
}

pool {
allow members of "virtualclass";
range 192.168.12.2 192.168.12.99;
}
}
 
Old 11-24-2010, 05:41 AM   #5
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Original Poster
Rep: Reputation: 58
OK, the setup is accepted by dhcpd, but it doesn't actually work, still assigns different ip's for mac's witch start with 08:00:

/var/lib/dhcp3/dhcpd.leases:
Code:
lease 192.168.11.59 {
  starts 3 2010/11/24 11:37:41;
  ends 3 2010/11/24 23:22:41;
  binding state active;
  next binding state free;
  hardware ethernet 08:00:27:de:be:09;
}
lease 192.168.11.55 {
  starts 3 2010/11/24 11:37:41;
  ends 3 2010/11/24 23:22:41;
  binding state active;
  next binding state free;
  hardware ethernet 08:00:27:d8:e9:47;
}
 
Old 11-25-2010, 12:22 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,242

Rep: Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024Reputation: 2024
I think you need to re-start the DHCP server to get it to re-read it's cfg? Or at least kill -HUP ...
 
Old 11-25-2010, 04:10 AM   #7
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Original Poster
Rep: Reputation: 58
That was pretty obvious that I need to restart dhcpd when updating configuration.
 
Old 11-25-2010, 06:16 AM   #8
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Ubuntu 10.10, Slackware 64-current
Posts: 2,124

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
I don't see anything wrong with the configuration. I would suggest the following:

1 - restart the DHCP and then look at syslog to see if it gave you any warnings or error messages that aren't sever enough to keep it from starting, but prevent it from working as intended.
2 - I searched for examples of how to perform this function and I saw a couple of minor variations on the syntax. Perhaps one of them will work for you.
a - put the MAC address that you are trying to match in between " marks. match if substring (hardware, 1, 2) = "08:00";
b - try substring (option hardware....
c - try adjusting the range on the hardware address to (hardware, 0,1) instead of (hardware 1,2)
3 - Is it possible that the DHCP is making an assignment from an earlier block in the configuration and not even getting to this one? Try putting a deny clause in the other block where the assingment is coming from. Along those lines, you may need to define the subnet, pool, or class towards the top of the file.
 
Old 11-25-2010, 09:11 AM   #9
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Original Poster
Rep: Reputation: 58
Ok, most of the idea didn't work, how do I do the deny idea?

P.S. option hardware doesn't work.
 
Old 11-25-2010, 10:25 AM   #10
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Original Poster
Rep: Reputation: 58
Here is my full configuration, if it helps:

Code:
ddns-update-style none;
authoritative;
default-lease-time 42300;
max-lease-time 84600;
log-facility local7;
option domain-name "internet.example.lan";
option domain-name-servers 192.168.11.1,192.168.11.100;
option routers 192.168.11.100;
option subnet-mask 255.255.255.0;
option ntp-servers 192.168.11.1;
option time-offset -0100;  # GMT+1
option wpad-url code 252 = text;
option wpad-url "http://local.example.org/proxy.pac\\n";

subnet 192.168.11.0 netmask 255.255.255.0 {
        range                   192.168.11.2 192.168.11.99;
        allow unknown-clients;
        allow booting;
        allow bootp;
        filename "pxelinux.0";
}

host wifi-router {
        hardware ethernet 00:1e:58:14:f8:81;
        fixed-address 192.168.11.99;
}

host laptop1 {
        hardware ethernet 00:1d:72:14:2b:ef;
        fixed-address 192.168.11.2;
}

host laptop2 {
        hardware ethernet 00:1e:37:8c:d6:73;
        fixed-address 192.168.11.3;
}

host laptop3 {
        hardware ethernet 00:0d:60:af:6c:b0;
        fixed-address 192.168.11.4;
}

host laptop4 {
	hardware ethernet 00:21:86:94:e5:68;
	fixed-address 192.168.11.4;
}

host storage {
	hardware ethernet 00:08:9b:bd:cd:3c;
	fixed-address 192.168.10.200;
}

host devel {
	hardware ethernet e0:cb:4e:c3:23:7a;
	fixed-address 192.168.11.10;
}

subnet 192.168.12.0 netmask 255.255.255.0 {
	class "virtualclass" {
		match if substring (hardware, 0, 1) = "08:00";
	}

	pool {
		allow members of "virtualclass";
		range 192.168.12.2 192.168.12.99;
	}
}
 
Old 11-27-2010, 05:29 AM   #11
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Ubuntu 10.10, Slackware 64-current
Posts: 2,124

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
In order to deny machines with these MAC addresses, you would simply add a statement like 'deny members of "virtualclass";' to the pool block for your main network.

I was reading some information on setting up OpenVPN with using a DHCP server instead of the pseudo DHCP used by OpenVPN. The author said that they used this same technique of creating an allow and a deny pool while matching on a substring of the MAC address to assign from. I have a similar setup, but don't have a deny clause. At any rate, it is worth trying and easy enough to do. At a minimum, it should tell you if the match substring is working properly.

Also, are there any warnings or errors in your syslog after you restart the DHCP that could indicate a typo or syntax error in your configuration file? I don't see anything wrong with your config file, but sometimes non printable characters or an unexpected " mark can cause some trouble.
 
Old 11-27-2010, 05:57 AM   #12
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Original Poster
Rep: Reputation: 58
No, there are no error with the config that I have, but it just doesn't work as it suppose to. Also how do I deny a class, when that class is specified in a different subnet, or I create this class also in the other subnet?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Blocking dhcpd address lease for specific MAC address kulman Linux - Server 8 03-30-2013 01:51 PM
Ethernet MAC Addresses database; MAC address-based processing cctualatin Linux - Newbie 1 04-14-2009 08:59 AM
Setting mac-address restrictions in dhcpd custangro Linux - Server 4 08-19-2008 06:33 PM
DHCPd based on Hardware Address Wildcard. Big_tummy Linux - Networking 1 05-23-2005 11:44 AM
Get IP based on Mac address sunmiewon Linux - Networking 4 01-31-2004 06:18 PM


All times are GMT -5. The time now is 03:45 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration