Mutant World

Friday, May 26, 2006

Big Changes and 2 Linux hacks

Long time, no blog entries.
I have to say that my life changed quite a bit: a newborn baby to take care of (Riccardo), a new job and soon a new house.

Another thing that I changed (less important than the above, but daily used) is the operative system: I've switched from Microsoft Windows to Kubuntu Linux.
The move was painful, especially at the beginning, and IMHO still not possible for an average user. For my mother it would have been impossible to figure out how to make wifi and video card working, let alone the modem, on my Lenovo T43p.

However, I recently found 2 useful Linux hacks.

First Hack: How to avoid duplicate commands in the bash history (when you hit arrow up in a shell).
Open ~/.bashrc; at the beginning of the file there is an entry such as:

export HISTCONTROL=erasedups

It's probably remarked, or has another value. Setting it to 'erasedups' made the hack.

Second Hack: How to correctly configure /etc/hosts when using DHCP.
It turns out that the dhcp client may run scripts when it binds (and when it releases).
The scripts for binding are /etc/dhcp3/dhclient-enter-hooks, and all the scripts inside directory /etc/dhcp3/dhclient-enter-hooks.d/.
Correspondent scripts for releasing are /etc/dhcp3/dhclient-exit-hooks and those inside directory /etc/dhcp3/dhclient-exit-hooks.d/.

The script dhclient-enter-hooks was missing in my configuration. I created it and put this inside:

#!/bin/bash
#
# This script updates /etc/hosts with the address received by the DHCP server
#
HOSTS=/etc/hosts
BACKUP=${HOSTS}.original
LOCAL=${HOSTS}.local

make_etc_hosts ()
{
cp -a $HOSTS $BACKUP
cat <<EOF > $HOSTS
# This file is generated by a script: do no edit; edit instead $LOCAL
# Created by $0 on `date`
127.0.0.1 localhost localhost.localdomain
$new_ip_address `hostname`

# The following lines are desirable for IPv6 capable hosts
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

# Entries from file $LOCAL, if any
EOF

test -f $LOCAL && cat $LOCAL >> $HOSTS
}

if [ "$new_ip_address" ]; then
make_etc_hosts
fi


With this script, /etc/hosts gets regenerated every time the dhcp client runs, and assigns the IP address received via DHCP to the hostname of the computer.
Still not perfect (if you have multiple network interfaces), but it's possible to improve it.
For me, for now, does the job :)

0 Comments:

Post a Comment

<< Home