#!/bin/sh # global options passed by udhcpc # what to run # $1 - which command to run, possible are: bound|deconfig|nak|renew # router - routers address # subnet - the subnet # dhcptype - type of dhcp # interface - which iface gets configured # serverid - ip of the dhcd server # dns - dns to use # ip - ip-address to use # lease - lease time of a dhcp configuration # mask - network mask to use # renew dhcp leases bound() { local RESOLV_CONF="/etc/resolv.conf" local BROADCAST local NETMASK local i [[ -n ${broadcast} ]] && BROADCAST="broadcast ${broadcast}" [[ -n ${subnet} ]] && NETMASK="netmask ${subnet}" /sbin/ifconfig ${interface} ${ip} ${BROADCAST} ${NETMASK} if [ -n "${router}" ] then echo "deleting routers" while /sbin/route del default gw 0.0.0.0 dev ${interface} do : done metric=0 for i in ${router} do /sbin/route add default gw ${i} dev ${interface} metric $((metric++)) done fi echo -n > ${RESOLV_CONF} [[ -n ${domain} ]] && echo "domain ${domain}" >> ${RESOLV_CONF} for i in ${dns} do echo adding dns ${i} echo "nameserver ${i}" >> ${RESOLV_CONF} done } renew() { # same as bound() bound } deconfig() { /sbin/ifconfig ${interface} 0.0.0.0 } # what to do if a dhcp request failed nak() { echo "Received a NAK: ${message}" } case $1 in bound) bound ;; renew) renew ;; deconfig) deconfig ;; nak) nak ;; esac