How To Change The Hostname On A FreeBSD Machine?

The hostname is the name given to a computer so that it could be identified uniquely when connected to a network. The installer asks and setup the hostname while installing FreeBSD in a system.

Sometimes you may want to change the hostname after installing FreeBSD operating system to somewhat relevant to the service running on it or something else.

This article shows exactly how you can change the hostname of a FreeBSD machine.

How to check the hostname in FreeBSD

There are various ways to find the hostname of a FreeBSD machine. You can check it in your terminal, see the image below –

The highlighted part of this image that is the string “srvr02” is the hostname.

The other way is to use hostname command in your terminal to find the hostname on FreeBSD. If you run hostname command without any argument, it will display the hostname –

As you can see in the above image srvr02 is the hostname.

How to change the hostname for the current session only

If you want to change the hostname for the current session only then execute the following command in your terminal –

hostname [new_hostname]

For example –

hostname ftp-server

Once this command is executed this will immediately change the current hostname srvr02 to ftp-server. When you log out or reboot the system, the hostname will change to the previous one i.e. srvr02.

Now you can check the hostname by running –

hostname

How to change the hostname permanently

To make changes permanent across reboots, you need to edit the file /etc/rc.conf and also you need to replace any occurrence of hostname from /etc/hosts.

[alert color=”yellow”]You need to have root access for editing configuration files[/alert]

First open /etc/rc.conf using a text editor

vi /etc/rc.conf

And modify the given hostname to –

hostname="new_hostname"

For example –

hostname ="ftp-server"

Now open /etc/hosts file by using –

vi /etc/hosts

Here find and change any occurrence of the old hostname to the new one, finally save the changes and exit from the editor.

Hostname command options in FreeBSD

You can use the following command-line options with hostname command in FreeBSD –

-f – Includes domain name information in printed name, this is the default behavior

-s – Trim off any domain information from the printed name

-d – Using this will print domain information only

To know more about hostname see its manual page by running –

man hostname

Also, see the system configuration information by using-

man rc.conf

Leave a Comment