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.

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.

In FreeBSD/PCBSD:

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.

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!