FreeBSD Change Hostname without reboot

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 the /etc/rc.conf file is a good way to keep hostname persistent across the system reboot. Open the terminal application and type the following command.

ADVERTISEMENTS

Display the current FreeBSD hostname

Simply type the following command:
$ grep hostname /etc/rc.conf
OR
$ hostname
Sample outputs:
FreeBSD Show Hostname

FreeBSD change hostname command

The procedure to change the computer name on FreeBSD:

  1. 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.
  2. Next Edit the /etc/hosts file:
    sudo vi /etc/hosts
    Replace any occurrence of the existing computer name with your new one.
  3. Update hostname for the current session by typing the following command:
    sudo hostname new-name-here
  4. 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

This entry is 9 of 19 in the Linux/Unix Set hostname Tutorial series. Keep reading the rest of the series:
  1. Ubuntu Linux Change Hostname (computer name)
  2. Debian Linux: Change Hostname / Computer Name Permanently
  3. Linux change my hostname / computer system name
  4. Linux Change Hostname
  5. RHEL / Centos Linux 7: Change and Set Hostname Command
  6. OpenBSD Change Hostname
  7. CentOS Linux 5/6 Change Hostname Command
  8. Linux setting hostname and domain name of my server
  9. FreeBSD Change Hostname without reboot
  10. SuSe Linux Change Hostname without reboot
  11. How to set the hostname on Fedora Linux
  12. Ubuntu 18.04 LTS change hostname permanently
  13. Ubuntu set hostname permanently (computer name) command
  14. OpenSUSE Linux set hostname permanently (computer name) command
  15. RHEL 8 Linux set hostname permanently (computer name) command
  16. CentOS 8 Linux set hostname permanently (computer name) command
  17. Ubuntu 20.04 LTS set hostname permanently (computer name) command
  18. Set / Change FQDN on Ubuntu 20.04 LTS
  19. Alpine Linux - Setting system hostname
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.