OpenBSD Journal

Heads Up! - dhclient(8) and dhcpd(8) are now even better

Contributed by sean on from the sleep-wake-sleeps-some-more dept.

Reyk Floeter (reyk@) recently committed some changes to dhclient which will make it much easier to use laptops. The idea is that dhclient should wait in the background when the link state is inactive and re-awaken (and attempt a lease) when the link comes back up.

Before this update one would have to mess with ifstated and have it start and stop dhclient as needed. Now we can just let dhclient live happily in the background. A very nice day for the road-warrior.

On the other side of the DHCP equation, dhcpd(8) has been getting some attention as well. Bob Beck (beck@) has added some spamd like syncing to dhcpd such that you can have two identically configured daemons running (for example, a CARP environment) and have some fail-over action on failure. The leases will be maintained via the sync and allows for a bit of redundancy.

(Comments are closed)


Comments
  1. By Anonymous Coward (78.102.96.24) on

    Great news! Just a seconds ago I woke up my laptop, killed and restarted dhclient to read these news. Once again: great!

  2. By Anonymous Coward (213.221.123.174) on

    That's pretty cool!

    I read about dhclient too and I faced some unresolved questions:

    I can submit serval options with the DHCP-Packet like specifying the timeserver. Will this get handled by dhclient?

    Comments
    1. By Tom Van Looy (tvlooy) on

      > I can submit serval options with the DHCP-Packet like specifying the timeserver. Will this get handled by dhclient?

      Yes, you can. First of all you need to request the ntp-servers option in /etc/dhclient.conf (read the manpage).
      Next you have to extend the dhclient-script with a function:
      add_new_ntp() {
        if [ -n "$new_ntp_servers" ]; then
          perl -i -ne 'print unless /^server/' /etc/ntpd.conf
          for address in $new_ntp_servers; do
            echo "server" $address >> /etc/ntpd.conf
          done
          pkill -KILL ntpd && ntpd
        fi
      }
      
      Next, you just call the function at REBOOT or/and REBIND|RENEW,... This is an example of what happens in the logs ...
      May 2 22:35:51 kaat dhclient[30663]: DHCPREQUEST on bce0 to 255.255.255.255 port 67
      May 2 22:35:51 kaat dhclient[30663]: DHCPACK from 127.0.0.1
      May 2 22:35:51 kaat ntpd[2737]: Lost child: child terminated; signal 9 (Killed)
      May 2 22:35:51 kaat ntpd[27146]: ntp engine ready
      May 2 22:35:51 kaat dhclient[30663]: bound to 192.168.1.80 -- renewal in 7200 seconds.
      May 2 22:36:11 kaat ntpd[27146]: peer 192.168.1.7 now valid
      May 2 22:36:14 kaat ntpd[27146]: peer 192.168.1.6 now valid
      May 2 22:38:13 kaat ntpd[27146]: clock is now synced
      May 2 22:52:39 kaat ntpd[12672]: adjusting clock frequency by -12.976140 to -12.976140ppm
      

      Comments
      1. By Anonymous Coward (81.83.46.237) on

        > request the ntp-servers option in /etc/dhclient.conf (read the manpage).

        That's not nice, ... /etc/dhclient.conf says:

        # See dhclient.conf(5) for possible contents of this file.
        and
        # request subnet-mask, broadcast-address, time-offset, routers,
        # domain-name, domain-name-servers, host-name, lpr-servers, ntp-servers;

        There's nothing about ntp-servers in dhclient.conf(5) ... :-(

        Comments
        1. By Anonymous Coward (213.221.123.174) on

          > > request the ntp-servers option in /etc/dhclient.conf (read the manpage).
          >
          > That's not nice, ... /etc/dhclient.conf says:
          >
          > # See dhclient.conf(5) for possible contents of this file.
          > and
          > # request subnet-mask, broadcast-address, time-offset, routers,
          > # domain-name, domain-name-servers, host-name, lpr-servers, ntp-servers;
          >
          > There's nothing about ntp-servers in dhclient.conf(5) ... :-(

          I noticed the same.
          It looks for me that dhcpd can serve more informatiosn then the client even can handle or use. :-/

          It confuses me a littlebit imho right now.

          Comments
          1. By Anonymous Coward (81.83.46.237) on

            > It looks for me that dhcpd can serve more information then the client even can handle or use. :-/

            The client has to request the information from the server, it will not receive NTP servers if it does not ask for it. It is perfectly possible to request the option ntp (and others, like proxy etc.).

            The only thing that's not handled by dhclient is how to use this information (eg: use it with openntpd or ntp.org's implementation, ...). I guess this is the same for the proxy option (eg: use it on the command line, firefox, opera, what else ...).

            Comments
            1. By Anonymous Coward (213.221.123.174) on

              > > It looks for me that dhcpd can serve more information then the client even can handle or use. :-/
              >
              > The client has to request the information from the server, it will not receive NTP servers if it does not ask for it. It is perfectly possible to request the option ntp (and others, like proxy etc.).
              >
              > The only thing that's not handled by dhclient is how to use this information (eg: use it with openntpd or ntp.org's implementation, ...). I guess this is the same for the proxy option (eg: use it on the command line, firefox, opera, what else ...).

              Well but isn't dhcp ment to hand over this information to provide a autoconfiguration of the clients?!

              So if I tell dhcpd to spread my ntp-server I should assume that all clients get it, like the IP Range and other things. Or am I wrong? :(

              There plenty of dhcp-options but I'm seriously: I wouldn't know how I do request the most of these. I always assumed dhcp handles it itself?!

              Because if I would know the ntp-Server, the swap-Server (does anybody ever used this even?! I would be happy to get a example for this option just to play around with it! :) ) I could create a entry in the specific configuration-files.

              So if somebody is a dhcp-guru here I would be happy for some hints because reading the RFC does not realy clarify this for me. :)

              Comments
              1. By Anonymous Coward (81.83.46.237) on

                > Well but isn't dhcp ment to hand over this information to provide a autoconfiguration of the clients?!

                it does, if you let your client ask for the options

                > So if somebody is a dhcp-guru here I would be happy for some hints because reading the RFC does not realy clarify this for me. :)

                I think it has nothing to do with dhcp, dhcp delivers you this information.
                It's what you do with the information that is not covered by the dhcp protocol (I think), you have to implement it for your application of choice yourself ... (I think).

                RFC1533 talks about these DHCP Options.

                I would like to know if other people use special dhcp options as well. Or, how this was used in the past ...?

              2. By Anonymous Coward (155.212.34.122) on

                For the basic stuff, dhclient does the equivalent of ifconfig plus writing (or clobbering) /etc/resolv.conf.

                For less common requests you'll need to find out what, if anything it does with the data or else devise a system to scrape it from /var/db/dhcp/dhclient.leases.

                Of course, a unified system to dump such output in files so rc scripts could easily slurp it in would be nice.

      2. By mirabilos (2001:6f8:94d:4:2c0:9fff:fe1a:6a01) on http://mirbsd.de/

        > pkill -KILL ntpd

        > May 2 22:38:13 kaat ntpd[27146]: clock is now synced

        IMHO there needs to be a way to add/remove servers in
        ntpd without restarting it.

        Comments
        1. By Anonymous Coward (81.83.46.237) on

          > IMHO there needs to be a way to add/remove servers in
          > ntpd without restarting it.

          I'm unable to find anything like that in the manpages.
          Maybe you only have to -HUP it instead of -KILL but I didn't try it out.

        2. By Crypto fish (76.24.36.87) cryptofish@comcast.net on

          > > pkill -KILL ntpd
          >
          > > May 2 22:38:13 kaat ntpd[27146]: clock is now synced
          >
          > IMHO there needs to be a way to add/remove servers in
          > ntpd without restarting it.

          The reference version of NTP is in the ports tree. If you use it, you can add and remove servers with an ntpdc command.

          Enjoy!

      3. By Anonymous Coward (213.221.123.170) on

        > I can submit serval options with the DHCP-Packet like specifying the timeserver. Will this get handled by dhclient?
        >
        > Yes, you can. First of all you need to request the ntp-servers option in /etc/dhclient.conf (read the manpage).
        > Next you have to extend the dhclient-script with a function:
        >
        >
        > add_new_ntp() {
        > if [ -n "$new_ntp_servers" ]; then
        > perl -i -ne 'print unless /^server/' /etc/ntpd.conf
        > for address in $new_ntp_servers; do
        > echo "server" $address /etc/ntpd.conf
        > done
        > pkill -KILL ntpd
        > fi
        > }
        >
        >
        > Next, you just call the function at REBOOT or/and REBIND|RENEW,...
        > This is an example of what happens in the logs ...
        >
        >
        > May 2 22:35:51 kaat dhclient[30663]: DHCPREQUEST on bce0 to 255.255.255.255 port 67
        > May 2 22:35:51 kaat dhclient[30663]: DHCPACK from 127.0.0.1
        > May 2 22:35:51 kaat ntpd[2737]: Lost child: child terminated; signal 9 (Killed)
        > May 2 22:35:51 kaat ntpd[27146]: ntp engine ready
        > May 2 22:35:51 kaat dhclient[30663]: bound to 192.168.1.80 -- renewal in 7200 seconds.
        > May 2 22:36:11 kaat ntpd[27146]: peer 192.168.1.7 now valid
        > May 2 22:36:14 kaat ntpd[27146]: peer 192.168.1.6 now valid
        > May 2 22:38:13 kaat ntpd[27146]: clock is now synced
        > May 2 22:52:39 kaat ntpd[12672]: adjusting clock frequency by -12.976140 to -12.976140ppm

        I don't know perl so that's propably the reason your code confuses me a littlebit.

        Where does this script gets the new server IP from?
        From the variable "new_ntp_server"?
        Ok but wich process does set this variable and where?!

        I alsoplayed with the idea to use ntp directly with dhcp but the manpage of the client does not mention anything about how to "use" any option. It just allows me to reject leases with unknown options but it does not tell me where maybe some informations get stored or how I could handle them. :/

        By the way doesn't >> mean you add something to the file?
        So you might end up with a lot "server"-entries in this file, or?

        If I think about it all there's no mechanism to just temporary use a ntp-Server. It's like with mygate it seams. It simply gets overwritten or?

        Totaly off topic but it came right now up to my mind:
        I have this in mind: At home or in your little office you have a fixed set up. If you're on the road you may connect via a hotspot and you get dhcp. So this always kills your configuration. I personaly wrote a script wich restores my setup but this may could get handled differently if it would be possible to use dhcp without overwriting systemfiles in some way. ntp wouldn't be the only config wich may profits from such a behavior but I don't know if it's hard to do nor have the time to do so.

        Comments
        1. By Anonymous Coward (81.83.46.237) on

          > I don't know perl

          "perl -i -ne 'print unless /^server/' /etc/ntpd.conf"
          basically the perl command removes lines that start with server in /etc/ntpd.conf

          > From the variable "new_ntp_server"?
          > Ok but wich process does set this variable and where?!

          Yes, new_ntp_servers contains these servers.
          I'll look up where exactly this gets initialized.

          > the manpage of the client does not mention anything about how to "use" any option.

          The source of /etc/dhclient.conf does.

          > By the way doesn't >> mean you add something to the file?
          > So you might end up with a lot "server"-entries in this file, or?

          No because the perl script removes them every time.
          You just end up having the ones that the server distributes.

  3. By Anonymous Coward (66.42.182.233) on

    Excellent!
    The little details and handling of unique cases that makes everything a little better. Sure adds up.
    OpenBSD has come a long way in a few years for ease of use everywhere. Great progress!

  4. By Anonymous Coward (24.222.223.104) on

    This is a really nice addition, thanks!!

  5. By jared spiegel (70.101.0.7) jrrs@ice-nine.org on

    DHCPRELEASE for dhclient. how much would that cost me and who do i send the cheque to? isc-dhcp-client is not in base and as such using isc-dhcp-client seems suboptimal to me. last i grepped for -i release in the obsd dhclient code the only hit was a #define :(

    Comments
    1. By Anonymous Coward (81.83.46.237) on

      > DHCPRELEASE for dhclient.

      Why do you need it so badly?

      Comments
      1. By Henrik Gustafsson (gsson) on http://fnord.se/

        > > DHCPRELEASE for dhclient.
        >
        > Why do you need it so badly?

        Personally I don't need it, however my ISP acts up if I don't release my lease properly, which can cause problems when I change my obsd firewall for some other (actually seems to be the MAC address change it reacts to, max one lease per MAC per port or sth...and a really annoying 30 minute time-out). Say once a month it might actually be of use to me, so no biggie to me. Weird behavior, but quite common here in .se at least.

    2. By Anonymous Coward (24.37.242.64) on

      > DHCPRELEASE for dhclient. how much would that cost me and who do i send the cheque to? isc-dhcp-client is not in base and as such using isc-dhcp-client seems suboptimal to me. last i grepped for -i release in the obsd dhclient code the only hit was a #define :(
      >

      I would like it too, would be very nice. In the mean time, you could always write a small script that does the same, unless there's other specific reasons in which there might be other ways around. The only exception would be the 'release it back' to the DHCP pool still missing.

Credits

Copyright © - Daniel Hartmeier. All rights reserved. Articles and comments are copyright their respective authors, submission implies license to publish on this web site. Contents of the archive prior to as well as images and HTML templates were copied from the fabulous original deadly.org with Jose's and Jim's kind permission. This journal runs as CGI with httpd(8) on OpenBSD, the source code is BSD licensed. undeadly \Un*dead"ly\, a. Not subject to death; immortal. [Obs.]