#!/bin/bash # # goal is to do a fake dhcp request so that the dhcp server sees this mac so that DNS requests are processed # # Date: 2007-08-24 # Authors: Isaac Traxler, Matthew Eastman # for prereq in ifconfig grep cut netstat head awk dhclient do if ! type ${prereq} >/dev/null 2>&1 then echo "Command '${prereq}' is required but was not found!" >&2 exit 1 fi done # see if we're running as a script file if [[ "${reason}" ]] then case "${reason}" in REBOOT) interface=$(netstat -nr | grep '^0' | head -n1 | awk '{print $NF}') curr_ip="$(ifconfig ${interface} | grep 'inet ' | cut -d':' -f2 | cut -d' ' -f1)" if [[ "${new_ip_address}" != "${curr_ip}" ]] then echo "WARNING! DHCP server gave us ${new_ip_address} instead of ${curr_ip}" >&2 fi ;; esac exit fi if pidof dhclient > /dev/null then echo "dhclient already running; doing nothing" exit 1 fi interface=$(netstat -nr | grep '^0' | head -n1 | awk '{print $NF}') if ! dhclient -q -1 -n -sf "$0" ${interface} then echo "Error: dhclient failed" >&2 exit 1 fi killall dhclient