Search this site


Metadata

Articles

Projects

Presentations

dhclient and dhclient-exit-hooks

Using DHCP on resnet only gives me search rit.edu as far as search domains. So, I got bored and wrote a small script to add useful domains for me. This is done using a feature of ISC's dhcp program, dhclient, called dhclient-exit-hooks. This is a shell script that is run when dhclient finishes fetching you an IP address.
This will add csh.rit.edu and cs.rit.edu to the search line in my /etc/resolv.conf.
Requires: a version of sed that supports inline editing (the -i option)

#!/bin/sh

DOMAINS="csh.rit.edu cs.rit.edu"

for dom in $DOMAINS; do
        grep "^search.*\b$dom\b" /etc/resolv.conf > /dev/null 2>&1 || 
        sed -i -e "/^search/ s/$/ $dom/" /etc/resolv.conf
done