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

[FreeBSD] How to Install FreeBSD OS, Step by step guide using a virtual machine

This post was last updated on November 3rd, 2020 at 05:18 pmTake a deep breathe and be sure that you have at least an hour of time. We have to

FreeBSD 0 Comments

How To Setup And Use PF Firewall On FreeBSD 12.1?

A firewall is a network security system that monitors incoming and outgoing network traffic flows through a system. It allows or blocks the data packets based on a set of

FreeBSD 0 Comments

[FreeBSD] How to allow Root access on FreeBSD over ssh protocol

This post was last updated on November 3rd, 2020 at 05:37 pmBy default FreeBSD does not allow root access over ssh protocol. So if you need to log on to

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply