How to Change the Hostname on a Linux Machine

How to Change the Hostname on a Linux Machine

Sometimes you wanted to change the Hostname on a Linux machine like on your Ubuntu PC or a Fedora machine or any other Linux distro like a Citrix XenServer to somewhat relevant to the service running on a server or say you have some slogan of yours that you want to put as a Hostname on your computer. Here I will show you how exactly you can change the Hostname on a Linux powered computer machine.

If you are a newbie to Linux then you might be wondering what is a Hostname and where can you find it on a Linux machine?
When you type the following command on a Linux machine:

uname -a

You will get similar outputs as below:

Linux 2.6.18-308.20.1.el5 #1 SMP Tue Nov 6 04:38:29 EST 2012 x86_64 x86_64 x86_64 GNU/Linux

The string “infysim-machine” is the hostname or system name you can say. Sometimes the hostname will be visible on your command prompt itself. Like this:

[email protected]:~$

The “root” is the username and the “infysim-machine” is the Hostname.

Can I change the Hostname for the current session only?

Yes. Instead of changing the Hostname permanently if you want it to be changed for the current session only then yes you can do that easily but you need to be a ROOT user.
Just follow the below command to change the Hostname for the current session only and not permanently:

[email protected]:/# hostname
[email protected]:/# hostname new_hostname

The hostname command (the 1st command) will print the current hostname set in the system.
The second command hostname NEW_HOSTNAME will change the hostname temporarily.

Hostname changes will be lost after logout or machine reboot.

How to change the Hostname permanently?

Usually the Hostname string is stored in a file. The filename may be different for different platform.
For Ubuntu and Fedora the file is located at: /etc/hostname and for Citrix Linux machine the file is at /etc/hosts. The file content may be looking like this:

[email protected]:/# cat /etc/hostname

Or on a Citrix machine it may be looking like this:

[email protected]:/# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.	localhost.localdomain localhost

Open the file and change the string to a desired one:

[email protected]:/# vim /etc/hostname
[email protected]:/# vim /etc/hosts
#Change the current hostname to something you want: [Ubuntu and Fedora]
or [Citrix]

In some cases the /etc/hostname will have only the hostname without the domain name string at the end:

[email protected]:/# cat /etc/hostname

Open the file and change the string to a desired one:

[email protected]:/# vim /etc/hostname

#Change the above name to something you want:

Previous Here Is How To Learn Android Application Development
Next How to Configure vncserver in Fedora

About author

siba 698 posts

A B.Tech degree holder with more than 5 years of experience on Embedded Systems design domain. He has worked on Aerospace domain, NAND storage, Server storage and Wireless networking.

View all posts by this author →

You might also like

Embedded Linux 0 Comments

How to Download, Extract and update the Linux Kernel source

When you are starting to learn Linux programming or Device driver development, then the first thing you need is the Linux Kernel which is available in a zipped archive format

Embedded Linux 1Comments

How to Configure vncserver in Fedora

Vnc server and vnc viewer is used to Remote Access in most of the Linux machines like Fedora, RHEL, Ubuntu or any other Linux distro. Sometimes it is necessary for


  1. Valuɑble info. Fortunate me I discоvered your web site by chance,
    and I’m surprised why this twist of fate did not took
    place in advance! I bookmarked it.

  2. I’ve read a few ɡood stuff һere. Certainly valսe Ƅookmarking for revisiting.
    I wonder how ɑ lot effоrt you рut to make tһis sort of magnificent informative web

  3. I visit daily a few web pɑges and blogs to reаd content,
    but this weblog provides feature based writing.

  4. Grᥱat info. Luckу mᥱ I found your blog by chance (stumbleupon).
    ӏ have bookmarked it for later!

Leave a Reply

Only registered users can comment.