Bug#239121: dhclient dumps such info into dhclient.leases, I think.
Joshua Kwan wrote:
> On Sun, Mar 21, 2004 at 11:23:54AM +1100, Andrew Pollock wrote:
>> The installer currently defaults the hostname of a new installation to
>> "debian". I think it would be sensible for it default to whatever
>> hostname is provided via DHCP, if one is, otherwise fall back to
>> defaulting to "debian".
>
> It could be done but I've no clue how to glean the DHCP-sent hostname
> from dhclient's output. Can you give me any pointers?
Hmm. I believe that it's in /var/lib/dhcp/dhclient.leases.
The last lease is always the correct one. So, something vaguely like this:
tac /var/lib/dhcp3/dhclient.leases \
| grep -m 1 'option host-name' \
| sed 's/ *option *host-name *\"\([^ ]*\)\"\; */\1/'
(If it's not set in any lease, there won't be an 'option host-name "foo";'
line, so this will return the empty string.)
I'm using dhclient3 rather than dhclient, so I may be wrong; also, my ISP
doesn't send a host-name, so I'm just using educated guesswork here.
Reply to: