How to change the hostname on Linux?

How to change the hostname on Linux?

This tutorial explains how to set or the change hostname from the command line on your Linux server. The hostname is also often referred to as a Fully Qualified Domain Name (FQDN hostname).


1. Display hostname.

Use the following command to display your server hostname.

Command: hostname -f

You can add the -f flag stands for full, because in some cases only a part of the actual hostname may be visible.


2. Set a new hostname.

Command: hostname <new_hostname>

Command: hostnamectl set-hostname <new_hostname>


3. Other methods.

If none of the above examples work, you can edit the /etc/hostname file and the/etc/hosts file and replace the default occurrences of the hostname with the correct one.



  1. Pingback: How to install cPanel WHM on your CentOS 6, 7? - Tiny Tumbleweed

  2. Pingback: How to install CentOS Web Panel on CentOS 7 OS? - Tiny Tumbleweed

  3. Pingback: How to install Vesta Control Panel on CentOS 7? - Tiny Tumbleweed

  4. Pingback: How to install Virtualmin on CentOS 7? – Tiny Tumbleweed

  5. Pingback: How to install Kloxo MR panel on CentOS 7? – Tiny Tumbleweed

  6. Pingback: Fully Qualified Domain Name (FQDN) – Tiny Tumbleweed

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.