How to change hostname in Fedora Linux permanently

ADVERTISEMENTS



What is hostname?

How do I change the hostname of a Fedora Linux system permanently using the command line tools from localhost to fedora28-nixcraft? How do I change hostname in Fedora Linux permanently from localhost.localdomain to fedora28-nixcraft?You can use the hostnamectl command to display or set the Fedora Linux system’s host name. In this tutorial,using various methods.

A hostname is nothing but your computer or server name. One can use the hostname to identify and define itself on a network. For example, hostname www13 indicates a web server. Sometimes you setup hostname as a fully qualified domain name (FQDN) such as www13.rack01.nixcraft.com or simply www.nixcraft.com.

Rules for naming hostname on the Fedora Linux

Rules are pretty simple. A hostname on Fedora Linux may only contain letters a-z, numerals 0-9, and dashes (-). An example is www-13. The FQDN for that server might be www-13.nixcraft.com.

How To change hostname in Fedora Linux server

Steps to change your hostname on Fedora Linux:

Login to your server: ssh user@server-name Become a root user: sudo -s or su - Run command: hostnamectl set-hostname new-name

Let us see steps in details to change a system’s hostname i.e. rename a computer/server name when using a Fedora Linux based system.

Find your current computer name

Type the following hostname command or hostnamectl command:

$ hostname

Sample outputs:

localhost.localdomain

$ hostnamectl

Sample outputs:

Static hostname: localhost.localdomain Icon name: computer-vm Chassis: vm Machine ID: c86ab4f4c14c435baff0597747b349d9 Boot ID: 2145ab2be9de49b6bca1837bb8d5a2f8 Virtualization: kvm Operating System: Fedora 28 ( Server Edition ) CPE OS Name: cpe:/o:fedoraproject:fedora: 28 Kernel: Linux 4.16.3- 301 .fc28.x86_64 Static hostname: localhost.localdomain Icon name: computer-vm Chassis: vm Machine ID: c86ab4f4c14c435baff0597747b349d9 Boot ID: 2145ab2be9de49b6bca1837bb8d5a2f8 Virtualization: kvm Operating System: Fedora 28 (Server Edition) CPE OS Name: cpe:/o:fedoraproject:fedora:28 Kernel: Linux 4.16.3-301.fc28.x86_64

Fedora change hostname

Let us change hostname in Fedora Linux. For example, change hostname to fedora28-nixcraft, enter:

$ sudo hostname fedora28-nixcraft

$ hostname

Sample outputs:

fedora28-nixcraft

As compared to hostnamectl command, hostname command just read or set the hostname for the current session. It only exists for compatibility reasons. Hence, I recommend using the hostnamectl command as discussed below.

How do I change Hostname Permanently on the Fedora Linux?

Edit the file /etc/hostname, enter:

$ sudo vi /etc/hostname

Delete the existing name and replace it with a new name:

fedora28-nixcraft

Save and close the file. You may also need to edit the /etc/hosts file, enter:

$ sudo vi /etc/hosts

Find all references to server1 and replace with server2:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.122.49 fedora28-nixcraft

Save and close the file. Please note that the host name is usually set once at system startup. This is an older method but still works on all versions of Fedora Linux.

How to set the hostname on Fedora Linux

With the latest version of Fedora Linux that uses systemd, it is possible to use a single command as follows:

# hostnamectl set-hostname {NameHere}

# hostnamectl set-hostname fedora28-nixcraft

Sample outputs:

