Differences between revisions 9 and 10
Revision 9 as of 2010-02-07 22:09:43
Size: 3554
Editor: ?JeromeAvond
Comment:
Revision 10 as of 2010-02-07 22:16:24
Size: 3586
Editor: FranklinPiat
Comment: formating
Deletions are marked like this. Additions are marked like this.
Line 57: Line 57:
{{{#!highlight
#!/bin/bash
 
usage() {
   echo "usage : $0 nouveau_nom_hote"
   exit 1
}

[ -z $1 ] && usage

ancien=`hostname`
nouveau=$1

grep $ancien /etc/ -rl 2>/dev/null | while read file
   do
      sed s:$ancien:$nouveau:g $file > ${file}.tmp
      mv ${file}.tmp $file
   done
}}}
Take care you'd better do a grep before...

=== Well linux spread old hostname (linux, debian, lenny, etc...) ===
{{{#!highilight sh
Line 60: Line 83:
  echo "usage : $0 nouveau_nom_hote"
  exit 1
 }
   echo "usage : $0 nouveau_nom_hote"
   exit 1
}
Line 64: Line 87:
 [ -z $1 ] && usage [ -z $1 ] && usage
Line 66: Line 89:
 ancien=`hostname`
 nouveau=$1
ancien=`hostname`
nouveau=$1
Line 69: Line 92:
 grep $ancien /etc/ -rl 2>/dev/null | while read file
 do
   sed s:$ancien:$nouveau:g $file > ${file}.tmp
   mv ${file}.tmp $file
 done

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

=== Well linux spread old hostname (linux, debian, lenny, etc...) ===

 #!/bin/bash
 
 usage() {
  echo "usage : $0 nouveau_nom_hote"
  exit 1
 }

 [ -z $1 ] && usage

 ancien=`hostname`
 nouveau=$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
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
Line 103: Line 104:
 done done
}}}

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

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

Rename a computer

Core networking

  • Update /etc/hostname

  • Update /etc/hosts, so local address(es) resolves with the new system name.

  • Reload the network configuration. You have two options
    • Reload configuration files
      <!> This will temporarily disconnect your system from the network (ssh usually resists short disconnection)

      invoke-rc.d hostname.sh start
      invoke-rc.d networking force-reload
      invoke-rc.d network-manager force-reload

      ToDo: is it useful to reload network-manager?

    • or the lazy way: Restart the system.

Application specific

avahi

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

  • invoke-rc.d avahi-daemon force-reload

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.

Exim

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

Message Of The Day

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

Cups

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

Mailname

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

Openssh server

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

other

  • (to be written) there must be others...

    Charlie: It was me who took you. Not the Others...

Idea of script to help you on

Complexe or unusual old hostname (albator, qskdfjh, turlututu, ...)

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

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

Well linux spread old hostname (linux, debian, lenny, etc...)

 #!/bin/bash
 
 usage() {
   echo "usage : $0 nouveau_nom_hote"
   exit 1
}

[ -z $1 ] && usage

ancien=`hostname`
nouveau=$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 s:$ancien:$nouveau:g $file > ${file}.tmp
   [ -f $file ] && mv ${file}.tmp $file
done

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


See also