OSETC TECH

Fedora Linux Permanently Change Hostname

This post will guide you how to change the hostname for a fedora Linux system permanently. You can change the hostname using the command line tools from A to B.

One Linux command HOSTNAMECTL can be used to display or change the hostname of Fedora Linux system. The below will teach you how to change the hostname via various methods.

HostName (FQDN or short Name)

The host name can help the system identify and distinguish itself on the entire network. You can set the hostname as a fully qualified domain name (FQDN) or just a short hostname that appears as part of a fully qualified domain name. For example, you can set the hostname of you system as fedoar1.osetc.com or just set its short name as fedora1.

Display the current hostname

If you want to check the current hostname of your fedora Linux system, just need to type the following hostname command:

#hostname

Outputs:

[root@fedora26 ~]# hostname
fedora26

Or you can run another command hostnamectl to get the current hostname:

#hostnamectl

outputs:

[root@fedora26 ~]# hostnamectl
Static hostname: fedora26
Icon name: computer-vm
Chassis: vm
Machine ID: 0ad00cdd519f42b6aff9846515c54cd2
Boot ID: 8809521864604e16b2f14c86bbe6dcfe
Virtualization: oracle
Operating System: Fedora 26 (Server Edition)
CPE OS Name: cpe:/o:fedoraproject:fedora:26
Kernel: Linux 4.11.8-300.fc26.x86_64
Architecture: x86-64
[root@fedora26 ~]#

Change Fedora Hostname

If you decide to change the hostname of fedora Linux system to something else. For example, change the hostname from fedora26 to fedora26-osetc. Just execute the hostname command as example below:

#hostname fedora26-osetc

Then execute hostname command again to check the changes.

Outputs:

[root@fedora26 ~]# hostname fedora26-osetc
[root@fedora26 ~]# hostname
fedora26-osetc

Note: the hostname is only set the hostname for the current session. And the hostname will be reset back to the previous hostname after you reboot the system. so if you want to change the hostname permanently, you should prefer to use the hostnamectl command or modify the hostname configuration file.

Change Fedora Hostname Permanently

Method 1: change hostname permanently using hostnamectl commmand

Changing the current hostname from fedora26 to fedora26-osetc permanently, just execute the following command:

#hostnamectl set-hostname fedora26-osetc

Then execute the hostname command to check the current hostname if it is changed.

[root@fedora26 ~]# hostnamectl set-hostname fedora26-osetc
[root@fedora26 ~]# hostname
fedora26-osetc

Method2: modifying the hostname configuration

You can also to modify the /etc/hostname configuration in fedora linux system to change the hostname permantently. Just do the following steps:

#1 edit the configuration file /etc/hostname, enter the following command:

# vi /etc/hostname

2# delete the existing hostname and enter into the following new hostname:

fedora26-osetc

3# save and close the file.

4# reboot your system or restart the network service.

5# you may be need to add one newly local name resolving in /etc/hosts, the format is like this:

192.168.1.45 fedora26-osetc

Then you can use the “hostnamectl status” or “hostnamectl” command to check the current hsotname information, enter:

#hostnamectl status

Outputs:

[root@fedora26 ~]# hostnamectl status
Static hostname: fedora26-osetc
Icon name: computer-vm
Chassis: vm
Machine ID: 0ad00cdd519f42b6aff9846515c54cd2
Boot ID: 8809521864604e16b2f14c86bbe6dcfe
Virtualization: oracle
Operating System: Fedora 26 (Server Edition)
CPE OS Name: cpe:/o:fedoraproject:fedora:26
Kernel: Linux 4.11.8-300.fc26.x86_64
Architecture: x86-64

Change Hostname Using Cockpit

You can also use Cockpit to change the hostname settings in your fedora linux system. Just do the following steps:

#1 go to the dashboard of your system, click System menu.

#2 select the Host Name to modify the current settings, type one hostname that you want to set in Real Host Name text box.

Change Hostname for Older Fedora releases

For older fedora linux system, you need to use the following method.

#1 edit the /etc/sysconfig/network file using vim or vi command.

#2 Find the ilne starting with “HOSTNAME=

#3 set the hostname for this system to this variable, for example, set the hostname to fedora1-osetc, like this:

HOSTNAME=fedora1-osetc

#4 save and close the file.

#5 restart network servcie.

Type the following command:

#service network restart