FreeBSD Change Hostname without reboot

/etc/rc.conf

ADVERTISEMENTS



Display the current FreeBSD hostname

I am a new FreeBSD user. How do I change hostname in FreeBSD using the command line option?You need to use the hostname command to show the name of the current host. The root user can set the hostname by supplying an argument to the hostname command. However, editing thefile is a good way to keep hostname persistent across the system reboot. Open the terminal application and type the following command.

Simply type the following command:

$ grep hostname /etc/rc.conf

OR

$ hostname

Sample outputs:



FreeBSD change hostname command

The procedure to change the computer name on FreeBSD:

Type the following command to edit /etc/rc.conf using vi text editor:

sudo vi /etc/rc.conf

Delete the old name and setup new name set in hostname variable. Next Edit the /etc/hosts file:

sudo vi /etc/hosts

Replace any occurrence of the existing computer name with your new one. Update hostname for the current session by typing the following command:

sudo hostname new-name-here Optional: Reboot the system to changes take effect or for testing purpose:

sudo reboot

How to change the FreeBSD server hostname without a system restart?

Type the following commands on FreeBSD server:

$ sudo hostname new-server-name-here

Next edit the /etc/rc.conf file and update hostname variable:

$ sudo vi /etc/rc.conf

Example:

hostname="new-server-name-here"

Save and close the file. Finally, edit the /etc/hosts file and update the lines that reads your old-host-name:

$ sudo vi /etc/hosts

From:

127.0.0.1 old-host-name

To:

127.0.0.1 new-server-name-here

Save and close the file.

hostname command options

Include domain information in the printed name. This is the default behavior:

$ hostname -f

Trim off any domain information from the printed name:

$ hostname -s

Only print domain information:

$ hostname -d

Getting more info

Read the following man pages:

$ man 5 rc.conf

$ man 1 hostname

