How to change the hostname in Linux and FreeBSD

Changing a Linux / FreeBSD hostname is an easy task. The hostname can be changed temporary or permanent. In this article, I will show you how to set a different hostname in the most used Linux distros and FreeBSD.

Watch Free Movies

How to temporary change the hostname:

The hostname command is used for changing the hostname. Without any option, if you type in your terminal hostname you will get the name of your host.

To temporary change your hostname, use hostname newname:
The following command works on both Linux and *BSD systems:
$ hostname new_host_name

If you change the hostname temporary, the old hostname will be restored at reboot.

How to permanently change the hostname:

In Debian/Ubuntu/Linux Mint/openSUSE:

Replace your old hostname with the new one in: /etc/hostname and /etc/hosts:

In Fedora/CentOS:

Open your /etc/sysconfing/network file as root and modify the HOSTNAME line to: HOSTNAME=new_host_name.
Also replace your old hostname with the new one in /etc/hosts.


Replace your old hostname with the new one in /etc/hosts and also edit the hostname line in your /etc/rc.conf to: hostname=”new_host_name”

The modifications made in the configuration files will apply at the first reboot.

Scroll to Top