Hooks
-----
-We provide example exit hooks for NTP (www.ntp.org) and ypbind (Linux).
+We provide example exit hooks for looking up the hostname in DNS,
+NTP (www.ntp.org) and ypbind (Linux).
There are not installed by default as they are platform dependant.
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd Apr 13, 2008
+.Dd Apr 22, 2008
.Dt DHCPCD 8 SMM
.Sh NAME
.Nm dhcpcd
.Pa /etc/resolv.conf .
If the hostname is currenly blank, (null) or localhost then
.Nm
-will set the hostname to the one supplied by the DHCP server, or look it up
-in DNS if none supplied.
+will set the hostname to the one supplied by the DHCP server.
.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.
need_hostname()
{
case "$(hostname)" in
- ""|"(none)"|localhost) return 0;;
+ ""|"(none)"|localhost|"${old_host_name}") return 0;;
esac
return 1
}
-lookup_hostname()
-{
- local h=
- # Silly ISC programs love to send error text to stdout
- if type host >/dev/null 2>&1; then
- h=`host ${new_ip_address}`
- if [ $? = 0 ]; then
- echo "${h}" \
- | sed 's/.* domain name pointer \(.*\)./\1/'
- return 0
- fi
- elif type dig >/dev/null 2>&1; then
- h=`dig +short -x ${new_ip_address}`
- if [ $? = 0 ]; then
- echo "${h}" | sed 's/\.$//'
- return 0
- fi
- fi
- return 1
-}
-
set_hostname()
{
- if [ -n "${old_host_name}" ] || need_hostname; then
- local name="${new_host_name}"
- [ -z "${name}" ] && name="$(lookup_hostname)"
- [ -n "${name}" ] && hostname "${name}"
+ if need_hostname; then
+ hostname "${new_host_name}"
fi
}
--- /dev/null
+# Sample exit hook to lookup the hostname in DNS if not set
+
+lookup_hostname()
+{
+ local h=
+ # Silly ISC programs love to send error text to stdout
+ if type dig >/dev/null 2>&1; then
+ h=`dig +short -x ${new_ip_address}`
+ if [ $? = 0 ]; then
+ echo "${h}" | sed 's/\.$//'
+ return 0
+ fi
+ elif type host >/dev/null 2>&1; then
+ h=`host ${new_ip_address}`
+ if [ $? = 0 ]; then
+ echo "${h}" \
+ | sed 's/.* domain name pointer \(.*\)./\1/'
+ return 0
+ fi
+ fi
+ return 1
+}
+
+do_hostname()
+{
+ if [ -z "${new_host_name}" ] && need_hostname; then
+ local hname="$(lookup_hostname)"
+ if [ -n "${hname}" ]; then
+ hostname "${hname}"
+ fi
+ fi
+}
+
+case "${reason}" in
+ TEST)
+ ;;
+ BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)
+ do_hostname
+ ;;
+ EXPIRE|FAIL|IPV4LL|RELEASE|STOP)
+ ;;
+ *)
+ echo "lookup_hostname: unsupported reason ${reason}" >&2
+ false
+ ;;
+esac
-#!/bin/sh
# Sample exit hook script for ntp
# Detect OpenRC or BSD rc
-#!/bin/sh
# Sample exit hook for ypbind
# This script is only suitable for the Linux version.