0

How can I configure Linux to reject a specific IP from DHCP server?

I mean I do not want my lan interface to get assigned 192.168.0.12 under any circumstances.

Is it possible? I have found on /etc/dhcp/dhclient.conf on can add a reject statement, but I think this meansto reject the whole DHCP server? I am a bit confused on this explanation:

reject cidr-ip-address [, ... cidr-ip-address ] ;

   The reject statement causes the  DHCP  client  to  reject  offers  from
   servers  whose  server identifier matches any of the specified hosts or
   subnets.  This can be used to avoid being configured by rogue  or  mis‐
   configured  dhcp  servers, although it should be a last resort - better
   to track down the bad DHCP server and fix it.
   .
   .
   .   
   reject 192.168.0.0/16, 10.0.0.5;

The above example would cause offers from any server identifier in the  entire
RFC  1918  "Class  C"  network  192.168.0.0/16, or the specific single address
10.0.0.5, to be rejected.

All I want is regardless of the DHCP server base address, the lan port never gets assigned by 192.168.0.12

What would be the correct line that I need to add to this conf file? something like this:

reject 192.168.0.0, 192.168.0.12;

Another problem is, I do not know the subnetmask that DHCP server uses.

3 Answers 3

0

DHCP does not provide a mechanism for this. If your DHCP client requests a new IP before the lease has expired, the server will most likely assign the same address. And at renewal, it will also assign the same address. This is by design to ensure the stability of the network. If your machine could refuse IP addresses it could potentially cause a DOS on the DHCP server.

The "reject" directive in dhclient.conf allows the client to choose which DHCP server it will use - not which IP address gets assigned.

If you do not want 192.168.0.12 assigned to your machine (although we have no idea why - it looks like a perfectly good IP address from here) then create a static mapping in your DHCP server to reserve it for a mac address which does not exist on your network.

0

You may not. The option you cite is for rejecting any offers from the specified server, not for rejecting offers that suggest specified address.

The only logic path in the DHCP client behaviour that allows for sending DHCPDECLINE message ("I don't want this IP") is when client determines that the address is already in use (see RFC).

However, you may opt for requesting certain IP, instead. E.g. it will ask DHCP server if it allows you to use certain specified IP address. For that, use the following:

interface "ethN" {
    send dhcp-requested-address 10.1.2.3;
}

It will be placed into DHCPDISCOVER and you will receive all the rest information, including netmask and gateway. This doesn't guarantee you'll be assigned this address; server is free to not acknowledge it and suggest another IP.

Read RFC2131 and remember that client is humble requestor and server has a full control of what to provide to whom. What it gives you, you take; you can't ask for another.

2
  • 1
    And upon receiving a DHCPDECLINE message, the server is supposed to react by trusting that that address is already in use and not give it to any other client, so you're effectively not just saying that you don't want it, but that it is not to be used. The server is also supposed to notify the admins, I guess their action depends on how they generally feel about you. Sep 11, 2023 at 9:02
  • ... also server is supposed to perform same check in advance, and only offer the address in case it finds the address isn't in use. As an admin I'd trust the server I manage and not the client which technically can violate the protocol. Sep 11, 2023 at 9:51
-1

Based on the documentation you quoted it would be

reject 192.168.0.12;

What I don't know because I've not tried it is whether rejecting an address that's been offered is equivalent to ignoring it completely as if it had never been sent, or if it triggers another part of the DHCP protocol that asks for another address instead

Consider addressing the question of whether it's better to be assigned this wrong address or to assigned no address at all

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .