I have a virtual server running Debian Squeeze. I can change the hostname by running the hostname new.host.name command or by editing /etc/hostname and then running /etc/init.d/hostname.sh, but after a reboot the hostname will be reset to the preconfigured hostname chosen by the server-hoster. I do not know which virtualization solution is used and I do not have access to an admin interface to change the hostname.

How can I change the hostname with a script each time the server boots?

  • 1
    Have you tried a simple grep of /etc/init.d to see if anything else is setting the hostname? Maybe just give up on setting the hostname, why do you think you need to change it? Not much really depends on it, most applications can be configured to not use the system-defined hostname. – Zoredache Oct 5 '12 at 17:01

One simple, albeit slightly dirty method for this would be to put hostname yourhostname into /etc/rc.local.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.