Change hostname in debian

A better way to change the hostname in debian systems.

# hostname -f
geminus


Sanity-check the list of /etc/* files in which the hostname appears.
# cd /etc
# grep -ril `hostname -f` /etc |tee hostname.files.list
/etc/mailname
/etc/hostname
/etc/exim4/update-exim4.conf.conf
/etc/hosts
/etc/ssh/ssh_host_rsa_key.pub
/etc/ssh/ssh_host_dsa_key.pub
/etc/ssh/ssh_host_ecdsa_key.pub
The above list seems fine but imagine what it would happen if the hostname was eth or work.

Save each file that contains the hostname to file.0 and replace geminus (old hostname) with gem (new hostname).
# perl -i.0 -p -e 's/geminus/gem/g;' `cat ./hostname.files.list`


Restart services (ssh and exim in this case) or better reboot the system if you can afford it.
# reboot




Change the hostname in debian systems