OpenBSD Change Hostname

last updated in Categories ,

I am a new OpenBSD Unix user. How do I change my hostname under OpenBSD operating system using the cli?

The hostname command displays the name of the current OpenBSD server or host. The superuser (root) can set the host name by editing a /etc/myname file. This is used at system boot time by netstart to initialize the hostname.

How to display hostname on OpenBSD

Type the any one of the following command
# hostname
# cat /etc/myname

Sample outputs:

openbsd.nixcraft.in

OpenBSD Change Hostname Commands

OpenBSD Chane Host Name

Simply login as root:
$ su -
OR
$ doas -s
Type the following command to change/update your hostname:
# echo "new-hostname.domain.com" > /etc/myname
# echo "server.nixcraft.in" > /etc/myname
# echo 'unixbox' > /etc/myname

Or edit using a text editor such as vi:
# vi /etc/myname
From the man page:

/etc/myname contains the symbolic name of the host machine. The file should contain a single line specifying the fully qualified domain name (FQDN) of the system (e.g. host.example.com). The name must be resolvable, either by matching a hostname specified in /etc/hosts (see hosts(5)) or through DNS (see resolv.conf(5)). The hostname is set via the hostname(1) utility at boot time. See hostname(7) for a description of hostname resolution.

During the system boot, netstart is executed. netstart performs the various operations including setting up the machine’s name. You can reboot box to test new settings:
# reboot
OR just set hostname at the cli i.e. no need to reboot the server:
# hostname server.nixcraft.in
You must edit /etc/hosts file too:
# vi /etc/hosts
Rename all old hostname to new hostname if present in that file. For more info see the following man pages:
$ man hostname
$ man 5 myname
$ man 5 hosts
$ man 8 netstart
$ man 1 su
$ man 1 doas

This entry is 6 of 16 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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

1 comment

  1. To make hostname changes effective, one could issue this command:
    hostname `cat /etc/myname`

    Still, have a question? Get help on our forum!