Translation(s): English - Italiano


Rename a computer

This page explains how to change a system's hostname (i.e. rename a computer/server)

Executive summary: hostname(1) isn't enough.

Core networking

Application specific

avahi

Avahi is used to publish (announce) local services. If you tweaked /etc/avahi/* you should run:

CUPS

Adjust /etc/printcap . You need to restart the service.

ejabberd

Refer to the Change Computer Hostname section of the ejabberd Installation and Operation Guide.

Exim

Adjust /etc/exim4/update-exim4.conf.conf (hostname=). You need to restart the service.

Mailname

Adjust /etc/mailname. You don't need to restart the service.

Message Of The Day

Adjust /etc/motd. You don't need to restart a service.

OpenSSH server

Adjust /etc/ssh/ssh_host_rsa_key.pub, /etc/ssh/ssh_host_dsa_key.pub and /etc/ssh/ssh_host_ecdsa_key.pub (root@hostname at the end). You need to restart the service.

ssmtp

Ssmtp is a light weight, send-only SMTP server.

Adjust /etc/ssmtp/ssmtp.conf (hostname=, etc.). You don't need to restart the service.

sysklogd

In order to make new hostname appear on syslog you should restart sysklogd service

Idea of script to help you on

Intrusive script

Please understand that this script is dangerous. You should check if all the files listed by grep -rl "$ancien" /etc must really be modified before launching this script:

   1 #!/bin/bash
   2 #
   3 usage() {
   4    echo "usage : $0 <new hostname>"
   5    exit 1
   6 }
   7 
   8 [ "$1" ] || usage
   9 
  10 old=$(hostname)
  11 new=$1
  12 
  13 grep "$old" /etc/ -rl 2>/dev/null |
  14 while read file
  15 do
  16       sed "s:$old:$new:g" "$file" > "$file.tmp"
  17       mv -f "$file.tmp" "$file"
  18 done

Take care you'd better do a grep before...

Not-so intrusive script

#!/bin/bash
# 
usage() {
   echo "usage : $0 <new hostname>"
   exit 1
}

[ "$1" ] || usage

old=$(hostname)
new=$1

for file in \
   /etc/exim4/update-exim4.conf.conf \
   /etc/printcap \
   /etc/hostname \
   /etc/hosts \
   /etc/ssh/ssh_host_rsa_key.pub \
   /etc/ssh/ssh_host_dsa_key.pub \
   /etc/motd \
   /etc/ssmtp/ssmtp.conf
do
   [ -f $file ] && sed -i.old -e "s:$old:$new:g" $file
done

Take care you'd better do a grep before...


See also