Updated: 9 November 2026 · Applies to: FreeBSD 14.4, 14.5 and 15.1 (from the FreeBSD Handbook and manual pages)
To change the hostname on FreeBSD without a reboot, run two commands as root: hostname server1.example.com changes it immediately, and sysrc hostname="server1.example.com" saves it in /etc/rc.conf so it stays after the next reboot. You need both: the first alone is lost at reboot, the second alone only takes effect at the next boot.
Step 1: check the current hostname
hostname
According to the FreeBSD Handbook, the hostname is the fully qualified domain name (FQDN) of the host, and a system with no hostname set calls itself Amnesiac. The hostname manual page lists three options for printing it:
hostname -f: the full name including the domain (this is also the default).hostname -s: the short name only, without the domain.hostname -d: the domain part only.
Step 2: set the new hostname for the running system
Only the super-user can set the hostname. As root (or with sudo or doas if you have them installed):
hostname server1.example.com
The change is instant. Running services keep working; your shell prompt shows the new name the next time you log in or open a new shell.
Step 3: make it permanent with sysrc
The Handbook's command to change the hostname and keep it across reboots is:
sysrc hostname="server1.example.com"
sysrc edits /etc/rc.conf safely (by default it works on /etc/rc.conf and /etc/rc.conf.local, and new settings are written to /etc/rc.conf). Read the value back to confirm it:
sysrc -n hostname
You can also edit /etc/rc.conf by hand. The line should look like this, with only one hostname= line in the file:
hostname="server1.example.com"
Alternative: apply the value from rc.conf
If you have already put the new name in /etc/rc.conf, you can apply it without typing it twice. The boot script /etc/rc.d/hostname reads the hostname variable from /etc/rc.conf and runs hostname with it, and you can run that script at any time:
service hostname start
It prints Setting hostname: followed by the name. If hostname is empty in rc.conf, the script warns that $hostname is not set and changes nothing.
Step 4: update /etc/hosts
Some programs, mail servers in particular, look the hostname up, so add the new name to /etc/hosts as well. The Handbook describes /etc/hosts as a simple database that maps host names to IP addresses. Replace 203.0.113.10 with your server's IP address:
203.0.113.10 server1.example.com server1
Remove or change any line that still has the old name. For a public server, also create an A record (and AAAA for IPv6) for the new name at your DNS provider, and ask your hosting provider to set the reverse DNS (PTR) if the server sends email.
Hostnames inside a FreeBSD jail
A jail starts with the name set by the host.hostname parameter in the host's /etc/jail.conf. According to the jail(8) manual, a jail may change its own name with hostname by default (allow.set_hostname), and the /etc/rc.d/hostname script only sets the name inside a jail when that is allowed. To rename a jail permanently, the safest place is host.hostname in /etc/jail.conf on the host, followed by a restart of the jail.
Renaming a directory on FreeBSD
If you came here looking for how to rename a folder rather than the machine: use mv, exactly as on Linux. Renaming /home/alice/old-name to new-name:
mv /home/alice/old-name /home/alice/new-name
Add -i to be asked before an existing file or directory is overwritten. More examples are in How to Rename Files and Folders in Linux (mv and rename), and the commands work the same way on FreeBSD.
Summary
hostname server1.example.com: changes it now.sysrc hostname="server1.example.com": keeps it after a reboot.- Update
/etc/hostsand DNS. - Check with
hostnameandsysrc -n hostname.
Changing the hostname on Linux instead? See How to Change the Hostname Permanently in Linux. For other FreeBSD tasks, see Sockstat command examples to find open ports in FreeBSD and How to check hard drive health on FreeBSD. If you would rather have a FreeBSD administrator do the work, our Hire an expert engineers handle one-off server tasks on demand.
Official documentation: the FreeBSD Handbook (chapter Network, section Setting the hostname) and the hostname(1), sysrc(8) and rc.conf(5) manual pages, which you can read on your server with man hostname.