change hostname debian

Change the hostname of a debian host

To get an idea what configuration files may be you using the old-current hostname it helps to grep /etc/ for the old-current hostname, eg:
# grep -ril `hostname -f` /etc/
/etc/postfix/main.cf
/etc/hosts
/etc/hostname
/etc/mailname


Update /etc/hostname
# echo "ahost.ipduh.com" > /etc/hostname


Update /etc/hosts ,eg:
#/etc/hosts
#IP Address  FQDN             Alias1  Alias2  AliasN
192.0.2.11   ahost.ipduh.com  ahost


Update /etc/mailname
# echo "ahost.ipduh.com" > /etc/mailname


Update SSH Host Keys
Replace root@old_hostname with root@new_hostname --the last words-- in /etc/ssh/ssh_host_rsa_key.pub and /etc/ssh/ssh_host_dsa_key.pub
Restart the SSH deaemon.

For Postfix update myhostname= in /etc/main.cf and restart the daemon

For ssmtp update hostname= in /etc/ssmtp/ssmtp.conf

Many daemons have some hostname definition in their configuration files that may need to be changed.

If possible restart the system.

Debian Wiki Change Hostname

URI: http://alog.ipduh.com/2013/01/change-hostname-debian.html