Jump to content

FreeBSD change hostname


Linux Hint

Recommended Posts

In this quick lesson, you’ll see how the command line option is used to modify hostnames in FreeBSD. To cut to the chase, it requires you to use a variation of the hostname command, which, when issued unappended without any option, lists the current hostnames.

Listing hostnames in FreeBSD with hostname command

Launch the terminal and type in the command below to list the hostnames on your FreeBSD system:

$ hostname

change-hostname-FreeBSD_1.jpg
Or you can use the grep utility and specify the location in the command:

$ grep hostname /etc/rc.conf

Changing hostname in FreeBSD

As stated earlier, you’ll need to add a switch to get the hostname command to change hostnames. To make these changes consistent upon restart, you’ll be editing the configuration file located in /etc/rc.conf.

To configure the /etc/rc.conf file, use the nano editor and issue the following command:

$ sudo nano /etc/rc.conf

change-hostname-FreeBSD_2.jpg
Replace the name with a new one and launch the hostname variable.

Then make changes to the /etc/hosts file, again using the nano text editor:

$ sudo nano /etc/hosts

change-hostname-FreeBSD_3.jpg
Edit the file to remove the name from throughout the file and replace it with the new one.

Finally, to apply changes temporarily without a reboot, type in:

$ sudo hostname new-name-here

You should reboot anyway to see if the changes have been retained.

$ sudo reboot

Changing hostnames in FreeBSD without a reboot

Issue the following command:

$ sudo hostname freebsd11

Then make changes to the /etc/rc.conf using the command below:

$ sudo nano /etc/rc.conf

For better illustration, consider the following:

# hostname="new-server-name-here"

change-hostname-FreeBSD_4.jpg
Make sure to save the file before you exit it.

Lastly, you’ll need to modify the /etc/hosts file replaces the old hostname with the new one:s

$ sudo nano /etc/hosts

change-hostname-FreeBSD_5.jpg
Change the hostname from 127.0.0.1 old-host-name to 127.0.0.1 new-server-name-here:

$ hostname command options

Add the details regarding the domain with the name. use the hostname command with the –f option:

$ hostname -f

Use the –s option to remove the domain information:

$ hostname -s

To acquire details regarding the hostname, add the –d option to the hostname command:

$ hostname -d

change-hostname-FreeBSD_6.jpg
To read more on the topic, visit the pages below:

$ man 5 rc.conf

change-hostname-FreeBSD_7.jpg

$ man 1 hostname

change-hostname-FreeBSD_8.jpg

Wrapping up

That’s the end of the lesson. Hopefully, the instructions here worked out for you, and you’ve successfully changed the hostname on your FreeBSD system.

View the full article

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...