Monthly Archive for May, 2010

Ubuntu, DHCP and hostnames

I just worked out that Ubuntu won’t set the hostname according to what is returned from dhcp. This makes sense in some ways, but I was deploying a VM template and I wanted the hostname set by dhcp.

I am not using network-manager in the following examples. And honestly network-manager only makes life easier on a laptop, or desktop when operating wirelessly.

Make sure your network interface is set to dhcp, as network-manager is installed by default the relevant line may be commented out (also if your not using it, purge network-manager from your system). The relevant entries from my /etc/network/interfaces:


# The primary network interface
auto eth0
iface eth0 inet dhcp

Add an script in /etc/dhcp3/dhclient-exit-hooks.d. It should check if GDM is running, as after it has started up you should not change the hostname. My script read as follows:
/etc/dhcp3/dhclient-exit-hooks.d/set_hostname

# 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) | g
rep -q /usr/sbin/gdm ; then
	echo "$(date): GDM running, not changing host name"
	else
		hostname $new_host_name;
	fi
fi

That should be it. Though you may need to remove some incorrect entries from /etc/hosts, and remove /etc/hostname if the file contents are wrong.

Lucid and iPhone tethering

I am loving Ubuntu 10.04. It is a genuinely brilliant release.

It has very good iPhone integration too. What it is still lacking is some of the utilities to make tethering easy. For USB tethering you can you can use Diego Giagio’s ipheth driver. I haven’t yet found a PPA for lucid, so you will need to compile from source.

For Bluetooth Tethering, Ubuntu comes with a nice new version of blueman, but it does not have the tight integration with network-manager.

To install blueman:
# apt-get install blueman

Pair your 2 devices. Pairing between blueman and the iphone generally works (even when it says it failed).

The trick to getting the network tether to work everytime is by starting the connection from your iphone. Once bluetooth is connected you can then right-click on you phone in blueman and access the network-point.

Because blueman and network-manager are not integrated you need one final commnand:

# dhcliet bnep0