11

How do I assign an IP address specific to a mac address using dhcpd?

So far I have tried

host blah { hardware ethernet <mac address>; fixed-address <ip address>;}

in my dhcpd.conf. But after restarting dhcpd and the machine with the mac address in question I just get a random IP again.

crisron
  • 105
  • 4
adampolar
  • 113
  • 1
  • 1
  • 4

4 Answers4

8

This is perfectly fine format -- I use exactly the same. Only I append a comment in the end of line (in addition). This is excerpt from working dhcpd.conf:

host wrt45gl-etika  { hardware ethernet 00:21:29:a1:c3:a1; fixed-address ---.219.43.135; } # MSIE routeris WRT54GL

As @Christoph mentions, there may be global option declared (or service defaults used) which may impact a way IPs are assigned / may override it.

While migrating from dhcp3-server (v3) to isc-dhcp-server (v4) I needed to add some mandatory options and rewrite some declarations. But the structure of config file remained simple:

#
# Sample configuration file for ISC dhcpd for Debian
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)

ddns-update-style none;

# option definitions common to all supported networks...

option domain-name "mf.vu.---";
option domain-name-servers ---.219.80.11, ---.219.80.2, ---.171.22.22;

default-lease-time 2678400;
max-lease-time 2678400;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.

authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).

log-facility local7;


# The subnet that shares this physical network

shared-network TOTAL_MF {
 server-name "letta.mf.vu.--";

 subnet ---.219.43.128 netmask 255.255.255.192 {
  option routers ---.219.43.190;
  option broadcast-address ---.219.43.191;

  group {
    host wrt45gl-etika  { hardware ethernet 00:21:29:a1:c3:a1; fixed-address ---.219.43.135; } # MSIE routeris WRT54GL
    # ...
    host saulute        { hardware ethernet 00:21:28:10:f4:16; fixed-address ---.219.43.189;  } # Virtual Qemu PC NIC
  }
 }

 subnet 172.16.43.128 netmask 255.255.255.192 {
  option routers 172.16.43.129;
  option broadcast-address 172.16.43.191;

  group{
    host ligo           { hardware ethernet 08:00:20:7A:E2:70; fixed-address 172.16.43.179;   } #a225 ligo
    # ...
    host vumfsa2        { hardware ethernet 00:80:48:8d:12:f0; fixed-address 172.16.43.140;   } # 118
  }
 }
}

There I used no pool, no range declarations. There are only two subnet declarations (one followed by another).

There I got no random IPs assigned to my hosts which are declared here (tied to MACs).

Jasper
  • 204
  • 2
  • 8
saulius2
  • 266
  • 3
  • 5
  • Can I use host without subnet? I need to set the broadcast to be same as the ip itself, also I need to set netmask to be `255.255.255.255`. I still need to some `post-up route add` and `pre-down route del` work. Can I, or should I do all these here? – Qian Chen Jul 13 '15 at 16:59
  • @ElgsQianChen: I think this doesn't relate to the topic. – saulius2 Oct 10 '15 at 08:00
  • @QianChen, have you managed to assign IP with subnet being = `255.255.255.255` ? – saulius2 Apr 30 '20 at 14:37
2

There is no explicit mention anywhere in the dhcpd.conf man page (and I can't try it now), but I always assumed that there is only one statement allowed per line.

host blah { 
    hardware ethernet <mac address>; 
    fixed-address <ip address>;
}
Sven
  • 97,248
  • 13
  • 177
  • 225
2

I don't know your dhcpd.conf, but if you have an allow unknown-clients statement, you should add allow known-clients.

If I recall correctly, the fixed IP should not be inside the range your DHCP-Server hands out to clients.

When the host has an old address from the same DHCP-Server, the server may hand out the old lease as long as it is valid, i.e. lease time not expired.

It would help, if you could provide more of your config.

Christoph
  • 107
  • 9
  • Actually, I think is is correct, you create groups or subclasses of named clients on hardware identifiers and then give them an deny-unknown address-pool (and a separate address-pool to permit-unknown, if desired. – quadruplebucky Mar 14 '14 at 12:08
-3

You have too many colons in there:

From the dhcpd.conf man page:

         host ncd1 { hardware ethernet 0:c0:c3:49:2b:57; }
quadruplebucky
  • 5,041
  • 18
  • 23
  • 2
    That also truncates this fixed IP declaration, so this doesn't actually answer the OP's question. – Magellan Jul 22 '14 at 18:48