2011年11月21日 星期一

ubuntu 由 DHCP 取得 ip 以及 hostname

Step 1.
===/etc/networks/interface
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp



Step 2.
=== /etc/dhcp3/dhclient-exit-hooks.d/sethostname ======================
# This script sets the machine hostname to the hostname sent from the DHCP server.
# Beware, if this happens while X is running, there will be problems, so the script checks
# for a running gdm and does not change the hostname if it detects one.
# If you want to enable this script, change SETHOSTNAME to "yes"

SETHOSTNAME="yes"

if [ "$SETHOSTNAME" = "yes" ]; then
        if test -r /var/run/gdm.pid && ps -ef | grep $(cat /var/run/gdm.pid) | grep -q /usr/sbin/gdm ; then
                echo "$(date): GDM running, not changing host name"
        else
                hostname $new_host_name;
        fi
fi