OpenBSD Change Hostname

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 Change Hostname Commands

OpenBSD Chane Host Name

Simply login as root:
$ su -
$ doas -s
Type the following command to change/update your hostname:
# echo "" > /etc/myname
# echo "" > /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. 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
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 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

1 comment… add one
  • Michael Kremser Apr 23, 2014 @ 16:24

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

Leave a Reply

Your email address will not be published.

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