reading IP address given via DHCP

Levi Pearson levipearson at gmail.com
Wed Sep 25 08:52:02 MDT 2013


On Wed, Sep 25, 2013 at 12:52 AM, Dan Egli <ddavidegli at gmail.com> wrote:

> What he wants (and what I've been scripting for him) is so that when a new
> machine that has never booted onto that network connects for the first time
> (this is only for PXE booting. If a machine has it's hard drive then this
> doesn't work), it boots into a tiny NFS root who's only purpose is to
> record IP and MAC info, then obtain a hostname from the user. At this point
> it writes all this to the server and flags the server (semaphor file in
> this case, rather than sockets). Then a program on the server would take
> this information, record a new DHCP reservation for that MAC, and record
> the machine's IP in the local DNS program, and restarts both, at which
> point it deletes the semaphor file. Once the file is deleted, the script on
> the new workstation sees it, and reboots itself. Once this reboot begins it
> grabs a DIFFERENT nfs root (via a /tftpboot/pxelinux.conf/<MAC> file
> instead of reading /tftpboot/pxelinux.conf/default), and boots into the
> nfsroot for that computer. The reason he wants to do it this way is because
> he wants a separate NFS root for computers in office 1 vs in office 2, and
> for them to be on a separate subnet. This way, he doesn't have to update
> configuration files (like I said, lazy) when machines are added to the
> network. The network updates itself.

There are ways to update most DNS servers without rebooting them. See
http://en.wikipedia.org/wiki/Dynamic_DNS for some pointers.

> So, I wrote up a setup that does exactly that. I was just wondering if
> parsing ifconfig and grepping for the MAC and IP in there was the best way
> to obtain the information (I really dislike playing around with grep/cut
> combinations when I can avoid it) or if there was a better way. But if
> grepping ifconfig is that common, then I guess it works for me. It DOES
> work (as far as I can tell, I haven't had a chance to actually test it
> yet), but it just seems kind of ugly/convoluted to me. Oh well. What the
> boss/client wants, the boss/client gets, as long as it's not TOO
> unreasonable. :) Gotta love working with federal government employees.
> __NOT__.

Well, technically ifconfig is rapidly moving towards deprecation in
Linux, to be replaced by the more general `ip` tool.  And I prefer a
nice little awk script to grep/cut combinations.  Whenever you need to
munge a text file and sed is too weak but perl is extreme overkill,
awk is where it's at. Much of perl's file-munging capabilities are
shamelessly lifted from awk, so it shouldn't be terribly hard to pick
up.


More information about the PLUG mailing list