How To Change The Hostname On A FreeBSD Machine?

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.

You need to have root access for editing configuration files

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
Previous ubuntu luks2 install with f2fs using the live install media
Next [ubuntu] Grub Customizer won't install. 404 error. Repository not added.
 

About author

You might also like

FreeBSD 0 Comments

How To Install Or Remove Packages Using Ports Collection In FreeBSD?

This post was last updated on October 15th, 2020 at 01:00 amFreeBSD provides various tools as a part of its base system. In FreeBSD, there are two ways to install

Installation 0 Comments

FreeBSD: Install And Use Bash Shell

This post was last updated on August 1st, 2020 at 09:11 amIn Unix like operating systems, a shell is a program that interprets the command, executes, takes input(s), and prints

FreeBSD 0 Comments

How To Make A File Write Protected And Undeletable In FreeBSD?

This post was last updated on August 1st, 2020 at 10:19 amFreeBSD operating system has an extra security feature for files called file flags. It provides additional control over files,

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply