[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: DHCP and hostname

  Venkat> My linux machine is in a network where the IP addresses are
  Venkat> assigned using DHCP.  I use "dhcpcd" to get the IP address
  Venkat> but it also mangles my machine's hostname (probably because
  Venkat> the DHCP server is not properly configured).  Is there a way
  Venkat> to query the DNS server for the correct hostname from the
  Venkat> assigned IP address and assign it?  Can this be automated?
  Venkat> Thanks.

Sorry for coming in late on this thread.  

If I understand correctly, you want to update your hostname when DHCP
gives you a (new) IP address.  Here is what I do:

  1) In the dhcpcd call there is an option to execute a script after
the IP address gets BOUND.  Add that option to your call, in
/etc/init.d/dhcpcd, if it is not already there.  I don't remember the
option, off hand.

  2) In this script add a line that runs ifconfig and greps out your
local IP address.  Then it takes that field and inserts it into
/etc/hosts with sed.  I made a /etc/hosts.start that has my local IP
address as "XXX".  Then I have the script run
  sed -e "s/XXX/$new_ip/" /etc/hosts.start > /etc/hosts

  3)  Make sure that /etc/hosts has your fully qualified pathname in
it.  I have something like:
   <IP addr>  foo.bar.com foo

That should do it.  Pls note that I'm typing all of this from memory,
so you should check everything.  All the concepts should be solid

Mark Mabry				Tel: (978)250-3344 x264   
Avici Systems Inc.			Fax: (978)250-3377        
12 Elizabeth Dr.,			Email: mmabry@avici.com   
Chelmsford,MA 01824			Web: http://www.avici.com/

Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null

Reply to: