Change Hostname
Change Hostname
Changing the hostname in FreeBSD can be done in a few simple steps. Here’s how to do it:
Step 1: Change the Hostname Temporarily
To change the hostname temporarily (until the next reboot), you can use the hostname command. Open a terminal and run:
sudo hostname new-hostname
Replace new-hostname
with your desired hostname.
Step 2: Change the Hostname Permanently
To make the hostname change permanent, you need to edit the /etc/rc.conf
file. Open the file in a text editor, such as vi
or nano
:
sudo vi /etc/rc.conf
or
sudo nano /etc/rc.conf
Look for a line that starts with hostname=. If it exists, change it to your new hostname. If it doesn’t exist, add the following line:
hostname="new-hostname"
Again, replace new-hostname
with your desired hostname.
Step 3: Update the /etc/hosts File
It’s also a good idea to update the /etc/hosts file to reflect the new hostname. Open the file:
sudo vi /etc/hosts
or
sudo nano /etc/hosts
Find the line that contains the old hostname and change it to the new hostname. It might look something like this:
127.0.0.1 localhost
127.0.0.1 old-hostname
Change old-hostname to new-hostname:
127.0.0.1 localhost
127.0.0.1 new-hostname
Step 4: Reboot or Restart Networking
To apply the changes, you can either reboot the system:
sudo reboot
Or, you can restart the networking service:
sudo service netif restart
Step 5: Verify the Change
After rebooting or restarting the network, you can verify that the hostname has been changed by running:
hostname
This should display your new hostname.
By following these steps, you should be able to successfully change the hostname on your FreeBSD system.