Q. I’m using Ubuntu Linux. How do I change my hostname or the machine name?
A.. You need to use hostname command, which is used to either set or display the current host or domain name of the system. This name is used by many of the networking programs to identify the machine.
Following instructions should work on both Debian and Ubuntu Linux systems.
Task: Display current hostname
Just type hostname command print the name of the system:
Task: Change hostname
Set hostname to desktop.nixcraft.com:
# hostname desktop.nixcraft.com
Task: Change hostname permanently
You need to edit a file called /etc/hostname:
# vi /etc/hostname
Set new hostname:
Save and close the file.
A note for Redhat / CentOS Linux users
If you are using CentOS or Fedora or Redhat (RHEL) Linux, see this FAQ.
Q. I would like to change hostname and domain name for my Linux server. Where can I set the local hostname and domain name of my server?
A. You can use hostname command to show or set the system's host name and dnsdomainname command to show the system's DNS domain name. But the changes are temporary if you use these commands.
Local hostname and domain name of your server defined in text configuration located in /etc directory.
If you are using Red Hat or Fedora Linux
Use redhat-config-network GUI tool. Type following command and click on DNS tab > Setup hostname and domain name:
On other hand you can edit a text file. Find out and set up the value for HOSTNAME in the file /etc/sysconfig/network:
# vi /etc/sysconfig/network
Where, web is hostname and nixcraft.com is your DNS domain name.
If you are using Debian Linux
You need to edit /etc/hostname file and put hostname.domain.com in this file:
# vi /etc/hostname
Set or replace hostname:
Debian, Suse and other Linux distro support GUI tool called network-admin. Type following command and click on DNS tab > Setup hostname and domain name:
Please note that you must have properly configured DNS server to work FQDN based hostname. See how to configure Linux as a dns client.