This comprehensive Linux guide expects that you run the following commands as root user but if you decide to run the commands as a different user then ensure that the user has
sudo
access and that you precede each of the privileged commands withsudo
A computer hostname represents a unique name that gets assigned to a computer in a network in order to uniquely identify that computer in that specific network.
During the installation of the FreeBSD, the default hostname is set as “localhost”. But if you want to change the hostname to your own choice, you can follow the instructions in this tutorial. We will guide you to change the hostaname of your FreeBSD.
Displaying Current Hostname
You can display the current hostname of the system by running the following command
root@codesposts:~$ grep hostname /etc/rc.conf
OR
root@codesposts:~$ hostname
Changing The Hostname
You can change the hostname by running the following command on your FreeBSD System.
root@codesposts:~$ hostname new-hostname
Then run the following command to edit the /etc/rc.conf
file
root@codesposts:~$ vi /etc/rc.conf
In the file, search for the variable “hostname” and change it’s value to your new hostname. Then save the file and exit.
Then run the following command to edit the /etc/hosts
file
root@codesposts:~$ vi /etc/hosts
Then find the name of your old hostname in the file and change it to your new hostname
Find:
127.0.0.1 old-hostname
And change it to:
127.0.0.1 new-hostname
Then save and close the file.
Verification Of New Hostname
You can verify the new hostname by running the following command
root@codesposts:~$ grep hostname /etc/rc.conf
OR
root@codesposts:~$ hostname