amazon media file explorer download upload index folder image licenses menu widget Play Pause profile-settings more dots-two-horizontal dots-two-vertical more-vertical pending google-plus hangouts facebook instagram whatsapp spotify telegram twitter vine renren rss youtube twitch vimeo flickr dribble behance deviantart 500px steam github soundcloud skype reddit linkedin lastfm delicious stackoverflow pinterest xing flattr foursquare yelp World

Easy Guide To Setting A Hostname In Linux/Ubuntu

In this guide, you would learn what a hostname means, how to view a hostname and how to properly set up a hostname on your Linux system.


What is a Hostname in Linux?

A hostname is a name that is assigned to a device connected to a network and that identifies your server to the rest of the network.

As humans need a name to address each other, a computer or server also need a name to differentiate from one another, so basically, they are human-readable names that are used to identify a specific server or computers, for example, you can have "Faruq", "John", "Clark", and basically anything as your hostnames.

Bear in mind that a hostname differs from a domain name in the sense that the hostname is the name assigned to a device while a domain name is a hostname+DNS domain.

E.g if Computer 1 which is named Mary and Computer 2 which is named Jane is connected to a network named Family, the domain name of the first computer would be and the second would be

I guess you got the idea ;)

Viewing Your Hostname In Linux

There are a couple of ways to view your hostname, one way is to look at your shell prompt: e.g:
Hostname at shell prompt

You can see my hostname is devsrealmthe default prompt shows the hostname and would strip out any further names e.g if your fully qualified domain name is, your prompt will only show blog and nothing more.

If you want to view the fully qualified domain name, you can simply enter hostname the command:

fully qualified domain name

You can see the Fully qualified domain name is

The next step is showing you how to change the hostname...

Changing Hostname In Linux

To change the hostname, you can issue the following command:

sudo hostnamectl set-hostname

The above command changes the content of a text file called /etc/hostname, you can cross-check for your self by opening the file:

cat /etc/hostname


nano /etc/hostname

The above command would reflect the name you just changed to.

Once you've changed your hostname, the next step is updating the hostname in /etc/hosts file, the /etc/hosts file associates IP addresses with hostnames. If the hostname is missing in /etc/hosts file, it won't be able to resolve the hostname to an IP address anymore, so basically, you won't be able to serve a web page or do a DNS query.

To change the hosts file, open it in a text editor:

sudo nano /etc/hosts

This is my output:

 etc-hosts file

In my case, I would change the devsrealm to the name I added in the /etc/hostname, which is, save, and close.

That's' it!

Related Post(s)

  • How To Access Windows 10 Drive/Folder in VirtualBox

    To access Windows drive or folder in your Guest OS, you first of all, install VirtualBox guest utilities: sudo apt-get install virtualbox-guest-utils You then Add a shared folder by going into: Setti

  • Send Mail with Attachment Using Mutt in GNU/Linux

    Mutt is a powerful text-based mail client for Unix/Linux operating systems. It features color support, message threading, MIME support...

  • Using Pageant To Automatically Authenticate SSH key in Putty

    I can't count how many times I have typed my ssh key passphrase whenever my ssh connection times out, it is so annoying and repetitive. Well, thanks to the putty pageant, you can do that seamlessly.

  • Installing WP-CLI In a GNU/Linux Server

    WP-CLI is a command-line interface for WordPress. It can also be used with ClassicPress, as they are no differences in their usage, maybe just minimal if you are updating or downloading new ClassicPr

  • How To Send Mail To Multiple Addresses Using (mailx)

    In this guide, you'll learn a couple of ways you can send mail to multiple addresses using mailx. mailx is a utility program for sending and receiving mail. I assume you already have mailx command, i

  • Mounting and Unmounting Cloud Storage With (Rclone) in GNU/Linux

    Ever wondered if you could mount your preferred cloud storage as a virtual drive on your system? Thanks to Rclone, you can mount and access different kinds of cloud storage from a file manager, I'll