This is how to change the hostname as well as the domainname of a machine running Debian or a Debian-like OS.
gert@oldhostname:~# hostname mynewhostname
Now close your shell (or log out), open a new one and you'll see the hostname is changed.
You can do the same thing for any of the domain names, just exchange the
hostname command with any of the ones below (taken from the manpage of
domainname - show or set the system's NIS/YP domain name ypdomainname - show or set the system's NIS/YP domain name nisdomainname - show or set the system's NIS/YP domain name dnsdomainname - show the system's DNS domain name
Edit the file containing your hostname, for example, just overwrite it with the new one:
echo "mynewhostname" > /etc/hostname
Then, change the entries accordingly in
Usually only the line starting with
127.0.1.1 has to be modified.
Now, run the
hostname init-script to finish everything up:
for Debian or
service hostname start
Complaints after the last command about the service not running can be discarded; it's not a real service, rather it's just a script run at boot time.
To verify the system has picked up the new hostname,
hostname can show you what it sees.
# just print the hostname hostname # print the fully qualified domain name hostname -f