From: Roy Marples Date: Sun, 13 Apr 2008 13:17:03 +0000 (+0000) Subject: We now use either dig or host to lookup the hostname in DNS again. X-Git-Tag: v4.0.2~502 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=312840d8496b8610e0f3b054930ec9387aed3171;p=thirdparty%2Fdhcpcd.git We now use either dig or host to lookup the hostname in DNS again. --- diff --git a/dhcpcd.8.in b/dhcpcd.8.in index 36481bd0..71d964de 100644 --- a/dhcpcd.8.in +++ b/dhcpcd.8.in @@ -79,7 +79,8 @@ will also attempt to restart the respective services to notify them of the change. If the hostname is currenly blank, (null) or localhost then .Nm -will set the hostname to the one supplied by the DHCP server. +will set the hostname to the one supplied by the DHCP server, or look it up +in DNS if none supplied. .Nm then daemonises and waits for the lease renewal time to lapse. Then it attempts to renew its lease and reconfigure if the new lease changes. @@ -231,7 +232,8 @@ dhcpcd itself never does any DNS updates. .It Fl H , --sethostname Forces .Nm -to set the hostname as supplied by the DHCP server. +to set the hostname as supplied by the DHCP server, or look it up +in DNS if none supplied. .It Fl I , -clientid Ar clientid Send .Ar clientid diff --git a/dhcpcd.sh b/dhcpcd.sh index 12e90e4d..1861e3e1 100755 --- a/dhcpcd.sh +++ b/dhcpcd.sh @@ -1,5 +1,4 @@ #!/bin/sh -# # dhcpcd - DHCP client daemon # Copyright 2006-2008 Roy Marples # All rights reserved @@ -230,11 +229,23 @@ need_hostname() return 1 } +lookup_hostname() +{ + if type host >/dev/null 2>&1; then + host "${IPADDR}" | sed 's/.* domain name pointer \(.*\)./\1/' + elif type dig >/dev/null 2>&1; then + dig +short -x "${IPADDR}" | sed 's/\.$//' + else + return 1 + fi +} + make_hostname() { - [ -z "${HOSTNAME}" ] && return 0 - if need_hostname || yesno "${PEERHOSTNAME}"; then - hostname "${HOSTNAME}" + if yesno "${PEERHOSTNAME}" || need_hostname; then + local name="${HOSTNAME}" + [ -z "${name}" ] && name="$(lookup_hostname)" + [ -n "${name}" ] && hostname "${name}" fi }